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

Document when and why the gem is needed #4

Open
perlun opened this issue Aug 22, 2017 · 1 comment
Open

Document when and why the gem is needed #4

perlun opened this issue Aug 22, 2017 · 1 comment

Comments

@perlun
Copy link

perlun commented Aug 22, 2017

Hi,

Myself, as many others, have been thinking of "why can't we have comments in JSON", because it's really useful sometimes to be able to document the rationale behind things etc.

Anyway, I started thinking about it today again, and I found this gem of yours.

But then, before I tried using it, I tried just adding a comment in my JSON data, and surprisingly, the json gem accepted it without any complaints whatsoever!

2.4.1 :007 > json_with_comment = <<EOF
2.4.1 :008"> {
2.4.1 :009">   // This is a C++-style comment
2.4.1 :010"> }
2.4.1 :011"> EOF
 => "{\n  // This is a C++-style comment\n}\n"
2.4.1 :012 > JSON.parse(json_with_comment)
 => {}

json gem version 2.1.0 in the test.

I tried uninstalling the gem, and using the built-in JSON parser in Ruby; it also swallowed this input data without further ado.

Is this something that's been added recently? Does it only work with particular versions of the JSON gem? I think it would make sense to try and document some more around this, because many people like me probably just want the data to be "parseable", and it would make sense to let them know that this can be done with the tools they already have, "given that preconditions X, Y and Z are met."

@GiriB
Copy link

GiriB commented Dec 11, 2019

@perlun is correct. json ruby gem already has the logic to ignore comments while parsing.

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