groupon / cson-parser

Simple & safe CSON parser
BSD 3-Clause "New" or "Revised" License
133 stars 27 forks source link

Enable json-ld syntax #41

Open jmatsushita opened 9 years ago

jmatsushita commented 9 years ago

I've posted this here bevry/cson#61 but it might be something to consider as an option for the parser...?

Pasting the linked issue for convenience:

With JSON-LD the use of keys prefixed with the @ character is idiomatic. This means that the home page example:

{
  "@context": "http://json-ld.org/contexts/person.jsonld",
  "@id": "http://dbpedia.org/resource/John_Lennon",
  "name": "John Lennon",
  "born": "1940-10-09",
  "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}

Is converted with the @keys quoted.

"@context": "http://json-ld.org/contexts/person.jsonld"
"@id": "http://dbpedia.org/resource/John_Lennon"
name: "John Lennon"
born: "1940-10-09"
spouse: "http://dbpedia.org/resource/Cynthia_Lennon"

Would it be possible to add an option (--ld ?) to allow @keys not to be quoted for better readability, as in:

@context: "http://json-ld.org/contexts/person.jsonld"
@id: "http://dbpedia.org/resource/John_Lennon"
name: "John Lennon"
born: "1940-10-09"
spouse: "http://dbpedia.org/resource/Cynthia_Lennon"
charlierudolph commented 9 years ago
@context: "http://json-ld.org/contexts/person.jsonld"
@id: "http://dbpedia.org/resource/John_Lennon"
name: "John Lennon"
born: "1940-10-09"
spouse: "http://dbpedia.org/resource/Cynthia_Lennon"

is not valid coffeescript and this library uses coffeescript for parsing. Thus supporting this would probably be very complex.

jkrems commented 9 years ago

Hi @jmatsushita - thanks for the suggestion and sorry for the late response. As @charlierudolph pointed out - it's not quite easy to support because the cson-parser syntax is currently defined as a subset of CoffeeScript, reusing the CoffeeScript parser. So support would have to start in coffeescript itself.