I've been trying to figure out a good way to load JSON objects in Python. I send this json data:
{'http://example.org/about': {'http://purl.org/dc/terms/title': [{'type': 'literal', 'value': "Anna's Homepage"}]}}
to the backend where it will be received as a string then I used json.loads(data)
to parse it.
But each time I got the same exception :
ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
I googled it but nothing seems to work besides this solution json.loads(json.dumps(data))
which personally seems for me not that efficient since it accept any kind of data even the ones that are not in json format.
Any suggestions will be much appreciated.
This:
{'http://example.org/about': {'http://purl.org/dc/terms/title': [{'type': 'literal', 'value': "Anna's Homepage"}]}}
is not JSON.
This:
{"http://example.org/about": {"http://purl.org/dc/terms/title": [{"type": "literal", "value": "Anna's Homepage"}]}}
is JSON.
EDIT:
Some commenters suggested that the above is not enough.
JSON specification - RFC7159 states that a string begins and ends with quotation mark. That is "
.
Single quoute '
has no semantic meaning in JSON and is allowed only inside a string.