validating JSON from command line using `python -m jsontool` gives 'No JSON object could be decoded'

Question:

I have a data.json file that I’m validating through the command line using python’s json.tool, but it keeps giving me back an error message:

$ python -m json.tool < data.json
No JSON object could be decoded

Here are the contents of data.json:

$ cat data.json
{ "fields": 
    [
        [ "first_name", null, {} ],
        [ "last_name", null, {} ],
        [ "addr1", null, {} ],
        [ "addr2", null, {} ],
        [ "city", null, {} ],
    ]
}

I don’t have a problem with single quotes, nor is the file empty (obviously), so I’m not sure what’s causing the problem here.

Asked By: 3cheesewheel

||

Answers:

It was because of the trailing comma after the last nested list [ "city", null, {} ]. I accidentally left it in and JSON doesn’t allow them.

Answered By: 3cheesewheel
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.