8000 Option to remove quotes for keys in printer · Issue #92 · circe/circe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Option to remove quotes for keys in printer #92

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

Closed
chandu0101 opened this issue Nov 7, 2015 · 2 comments
Closed

Option to remove quotes for keys in printer #92

chandu0101 opened this issue Nov 7, 2015 · 2 comments

Comments

@chandu0101
Copy link
Contributor

Currently printer prints keys with string quotes

Sample(duration: Int)
Sample(123).asJson.noSpaces // { "duration" : 123} 

// with new proposal printer can print without quotes { duration : 123}

Use cases : Some API's(for example GraphQL) doesn't allow keys with quotes

Fix :
Looks like an easy one
https://github.com/travisbrown/circe/blob/master/core/shared/src/main/scala/io/circe/Printer.scala#L166

 if(keyWithQuotes) encloseJsonString(key)  else     appendJsonString(key)

// a new val in printer
val noSpacesAndKeysWithoutQuotes =  Printer(
    preserveOrder = true,
    dropNullKeys = false,
    indent = "",
   keyWithQuotes = false
  )

please review current proposal and let me know the feedback , i can send a PR :)

@travisbrown
Copy link
Member

Thanks, @chandu0101, but I'm a little hesitant to add this to core, for a few reasons:

  1. The result isn't valid JSON. In some cases circe can be configured to be more conservative than the JSON spec (e.g. it can maintain insertion order), but not less.
  2. If we did decide to support this syntax on the printing side, I'd prefer to support parsing it, and that's likely to be a lot more complicated.
  3. I know practically nothing about GraphQL, but at a glance it looks like it adds other syntax to JSON that isn't covered by this change (so you still can't use circe to produce arbitrary GraphQL).

Does this sound accurate? If there's demand for this, and if we can add parsing support (not necessarily using Jawn), I'd definitely consider including it in a new module.

@chandu0101
Copy link
Contributor Author

first of all thanks for prompt and detailed response

The result isn't valid JSON

End of the story, i thought its a valid JSON :(

I know practically nothing about GraphQL, but at a glance it looks like it adds other syntax to JSON that isn't covered by this change

Yeah GraphQL is JSON like query lang but its API'S(js clients) accepts valid js.Object's, looks like i am calling API in wrong way even though it works!. I think i actually need Json to scala.js js.Object/js.Dynamic which we can cover in #93 !

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
0