Filosoft / vabamorf

Eesti keele morfanalüsaator
Other
24 stars 14 forks source link

Sample JSON input files not compatible with Python's json.tool #3

Closed Kaljurand closed 10 years ago

Kaljurand commented 10 years ago

A recommended way of pretty-printing JSON files is Python's json.tool (see e.g. http://stackoverflow.com/questions/352098/how-can-i-pretty-print-json). The JSON files included as examples of input formats are not compatible with this tool.

$ python --version
Python 2.7.6
$ cat apps/cmdline/project/vc2010/etana/test.json | python -mjson.tool
Expecting property name: line 2 column 2 (char 4)
PRR24 commented 10 years ago

Probably the tool expects key names to be quoted, smth that is considered generally optional.

I guess the important part is that output files generated by the programs are compatible with the tools (keys are quoted). Programs accept input files with both quoted and unquoted keys.

kristiank commented 10 years ago

The JSON standard does not consider quotes to be optional, in fact, they need to be there! Quoting from the ECMA-404 The JSON Data Interchange Standard (http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf):

A JSON value can be an object, array, number, string, true, false, or null. An object structure is represented as a pair of curly bracket tokens surrounding zero or more name/value pairs. A name is a string. A string is a sequence of Unicode code points wrapped with quotation marks (U+0022).

Thus, the only tokens not needed to be enclosed with quotation marks are numbers and the tokens true, false and null. Arrays need to be enclosed with [ ] marks.

Please don't keep closing the Issue threads before solving them!

PRR24 commented 10 years ago

Yesterday, I closed an issue briefly before pushing the fix. I learned my lesson, today I did it in right order, so it would have been nice if you had checked it before commenting..

kristiank commented 10 years ago

I don't see that silently accepting non-quoted strings in input is conforming to the standard. So the test files were not generated by the program? If the output is always conformant, it's good.

When merging a pull request, you can add either: closes #IssueNumber or fixes #IssueNumber To make the fixing/closing of the issue more visible.

PRR24 commented 10 years ago

Yes, test files are for program input, not its output. So, as:

I would prefer not to continue with this thread :)

kristiank commented 10 years ago

Fine. Great that output is truly standards compliant.