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

encoding/json: Respect escape sequences in struct tags #15000

Closed
gibson042 opened this issue Mar 28, 2016 · 3 comments
Closed

encoding/json: Respect escape sequences in struct tags #15000

gibson042 opened this issue Mar 28, 2016 · 3 comments

Comments

@gibson042
Copy link
Contributor

It is impossible to serialize structs into JSON objects with keys containing certain characters, most notably commas (in contrast with all other ASCII punctuation, because they are used to separate key name from tag options). This could be corrected by interpreting escape sequences in the tags as if they were double-quoted strings, which is possible since backslash characters are reserved.

  1. What version of Go are you using (go version)?
    go version go1.5.1 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
  3. What did you do?
    Attempted to serialize a struct into a JSON object with fields containing commas: http://play.golang.org/p/2KgYUahN8a
  4. What did you expect to see?
{
 "a": "A:a",
 "b": "B:\u0062",
 "\\u0063": "EscapedC:\\u0063",
 ",": "Comma:\u002c",
 "\\u002c": "EscapedComma:\\u002c"
}
  1. What did you see instead?
{
 "a": "A:a",
 "b": "B:b",
 "EscapedC": "EscapedC:\\u0063",
 "Comma": "Comma:,",
 "EscapedComma": "EscapedComma:\\u002c"
}
@bradfitz bradfitz added this to the Unplanned milestone Apr 9, 2016
@bradfitz
Copy link
Contributor

bradfitz commented Apr 9, 2016

Is this a solution in search of a problem? Do people actually use commas in JSON object keys?

@gibson042
Copy link
Contributor Author

While it's probably not seen in the wild, I ran into this while trying to be thorough in testing. And even though the impact is low, having the mapping from struct tag to JSON key be non-surjective does seem unnecessarily flawed.

@bradfitz
Copy link
Contributor

Okay, let's close this then until there's a use case.

@golang golang locked and limited conversation to collaborators Apr 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants