Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 927
3cheesewheel Avatar asked Sep 20 '13 17:09

3cheesewheel


People also ask

How do you parse a JSON file in Python?

If you need to parse a JSON string that returns a dictionary, then you can use the json. loads() method. If you need to parse a JSON file that returns a dictionary, then you can use the json. load() method.

How do I decode a JSON file?

You just have to use json_decode() function to convert JSON objects to the appropriate PHP data type. Example: By default the json_decode() function returns an object. You can optionally specify a second parameter that accepts a boolean value. When it is set as “true”, JSON objects are decoded into associative arrays.


1 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.

like image 129
3cheesewheel Avatar answered Oct 08 '22 19:10

3cheesewheel