Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[noob] how not to escape nested JSON #2083

Open
vijayrajah opened this issue Oct 2, 2019 · 1 comment
Open

[noob] how not to escape nested JSON #2083

vijayrajah opened this issue Oct 2, 2019 · 1 comment

Comments

@vijayrajah
Copy link

vijayrajah commented Oct 2, 2019

I (trying) to create an API that responds with "IndentedJSON". The struct is like

type Mydata struct {
Name string
Location string
Data interface{}
Other string
}

The 'Data' field has JSON. When I use "IndentedJSON" I see the "outer" JSON cleanly rendered, but the inner JSON is escaped.
EX:

{
"Name": "Vijay",
"Location": "Loca1",
"Data": "{\"ids\":[\"AA\",\"BB\"]}",
"Other": ""
}

Is there an way to fix this? and print the "clean" JSON (unescaped JSON)

@guonaihong
Copy link
Contributor

Try this definition

type Mydata struct {
    Name string
    Location string
    Data json.RawMessage
    Other string
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants