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

Unexpected breaking behavior regarding backslashes #48

Closed
Heimrych opened this issue Dec 7, 2020 · 1 comment · Fixed by #53
Closed

Unexpected breaking behavior regarding backslashes #48

Heimrych opened this issue Dec 7, 2020 · 1 comment · Fixed by #53
Labels
bug Something isn't working

Comments

@Heimrych
Copy link

Heimrych commented Dec 7, 2020

Description

gojq removes backslashes from double quoted string keys.

Version

gojq 0.11.2 (rev: HEAD/go1.15.2)

How to reproduce:

1 - Setup a file with a JSON containing keys that include doublequotes and require backslashes. Example:

{
  "aliasColors": {
    "{statuscode=\"200\"} 200": "green",
    "{statuscode=\"404\"} 404": "semi-dark-purple",
    "{statuscode=\"500\"} 500": "dark-red"
  }
}

2 - Run gojq in file.

gojq '.' issue.json

Expected behavior: It parses the file along with the backslashes, just like jq.

{
  "aliasColors": {
    "{statuscode=\"200\"} 200": "green",
    "{statuscode=\"404\"} 404": "semi-dark-purple",
    "{statuscode=\"500\"} 500": "dark-red"
  }
}

Actual behavior: It removes the backslashes, turning the JSON invalid.

{
  "aliasColors": {
    "{statuscode="200"} 200": "green",
    "{statuscode="404"} 404": "semi-dark-purple",
    "{statuscode="500"} 500": "dark-red"
  }
}
@itchyny
Copy link
Owner

itchyny commented Dec 8, 2020

Thanks for reporting. I submitted a pull request to go-prettyjson library. But I noticed some inefficiency and low coverage of the lib, I'm thinking of switching to different lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants