. Advertisement .
..3..
. Advertisement .
..4..
I’ve been attempting to determine the best method for loading JSON objects in Python. I send this info in json, but I’m getting this error ” expecting property name enclosed in double quotes”:
{'http://example.org/about': {'http://purl.org/dc/terms/title': [{'type': 'literal', 'value': "Anna's Homepage"}]}}
I used json.loads(data)
to parse it before sending it to the backend, where it will be received as a string. But I’m getting the same exception:
ValueError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
I searched for a solution on Google, but nothing else seemed to work than json.loads(json.dumps(data))
, which I find to be less effective because it accepts all types of data, even those that are not in json format. Please help me. Thanks a lot.
The cause:
The file is not valid json.
The solution:
{‘a’:{‘b’:c,}} ^
To remove this com{‘a’:{‘b’:c,}ma, I wrote some simple code.
import json
with open(‘a.json’,’r’) as f:
I looked over your JSON data.
{‘http://example.org/about‘: {‘http://purl.org/dc/terms/title‘: [{‘type’: ‘literal’, ‘value’: “Anna’s Homepage”}]}}
in http://jsonlint.com/ and the results were:
Error: Parse error on line 1:
{ ‘http://example.org/
–^
The JSON problem is resolved by changing it to the following string: Expecting ‘STRING’, “, got ‘undefined’.
{
}
Instead of using single quotes, you can use double quotes to fix quickly:
bring json
forecast= []
def get_top_k_predictions(predictions_path):
get_top_k_predictions(“/sh/sh-experiments/outputs/john/baseline_1000/test_predictions.jsonl”)
The error is caused by invalid quotation characters provided to the json module, as the other solutions adequately illustrate.
In my situation, even after switching ” with” in my string, I still received the ValueError.
“ ” ‘ ’ ‘ ` ´ ” ‘
You may just run your string through a regular expression to remove all of these:
import re
raw_string = ‘{“key”:“value”}’
parsed_string = re.sub(r”[“|”|’|’|‘|`|´|”|’|’]”, ‘”‘, my_string)
json_object = json.loads(parsed_string).
Good luck!