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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With