why is this true:
import json
json.loads('{"A":2}')
but this is wrong:
json.loads('{"A":2,}')
OR
json.loads("['A':2]")
JSON is a subset of JavaScript. This means things that are valid JavaScript are not necessarily valid JSON.
{"A":2,} is valid JS (except in old IE versions), but not valid JSON['A':2} is not even valid JS since the braces do not match. If they matched, it would still be invalid JSON as JSON always uses " and never ' to quote strings.See http://json.org/ for the JSON specs.
json.loads("['A':2]"): is invalid there. Either define an object: {k:v, k:v, ...} or an array [v, v, ...]. That's how JSON is defined, you just have to remember it. Therefore: json.orgBecause the last two options are not a valid json
[ should match a ] (array) and a { should match a } (object)
{"A":2,}(trailing comma) and['A':2}([],{}mismatch, key not in double quotes) are not valid JSON. See json.org and jsonlint.com.