When loading a JSON body receiving error: "expecting ',' delimiter: line 1 column 18 (char 17)"?
It seems that you're treating the content of some_body
as a string since it's enclosed with double quotes. But inside of that string there's also quotation marks and now it's interpreted that the content of some_body
is [{
and then it breaks because directly after that is someId
rather than a comma. Thus the error:
expecting ',' delimiter: line 1 column 18 (char 17)
If the content of some_body
was actually meant to be a string then all the double quotes inside of it should be preceded by a double backslash (\\
) although in this case you'd have to parse the JSON twice - first the entire a_json
string and then the content of some_body
. However I think it would be easier to just remove the double quotes around the content of some_body
.
a_json = '{"some_body":
[{"someId":"189353945391","EId":"09358039485","someUID":10,"LegalId":"T743","cDate":"202452","rAmount":{"aPa":{"am":1500,"currId":"UD"},"cost":{"amount":1000,"currId":"US"},"lPrice":{"amount":100,"currId":"DD"}},"tes":{"ant":0,"currId":"US"},"toount":{"amnt":0,"currId":"US"},"toount":{"amt":210,"currId":"US"},"bry":"US","pay":[{"pId":"7111","axt":{"amt":2000,"currId":"US"},"mKey":"CSD"}],"oItems":[{"iIndex":0,"rId":"69823","provId":"001","segEntityId":"C001","per":{"vae":1,"ut":"MOS"},"pct":{"prod":"748"},"revType":"REW","rAmount":{"aPaid":{"amt":90000,"currId":"US"},"xt":{"amt":0,"currId":"USD"},"lPrice":{"amt":90000,"currId":"US"}},"stion":{"sLocal":"094u5304","eLocal":"3459340"},"tx":{"adt":{"adet":0,"currId":"US"},"era":"werTIC"
}}]}]}'
Also note that there's a missing closing square bracket near the end.
In your original string:
"werTIC"}}}]"}
Which should probably be:
"werTIC"}}]}]}
Now the desired item should look like this (I assume that 'aPa'
was meant to be 'aPaid'
):
desired_item = loaded_body['some_body'][0]['oItems'][0]['rAmount']['aPaid']['currId']
print(desired_item)
US
How to solve the error "ValueError: Expecting , delimiter"?
This seems to work:
import json
text = '''{"seasons":[{"season-type":"type1","start-day":10,"start-month":1,"end-day":31,"end-month":5},{"season-type":"type2","start-day":1,"start-month":9,"end-day":9,"end-month":1},{"season-type":"type3","start-day":1,"start-month":6,"end-day":30,"end-month":9}]}'''
obj = json.loads(text)
Your question has double quotes around the list:
text = '''{"seasons":"[{"season-type": ... ,"end-month":9}]"}'''
^ ^
"ValueError: Expecting , delimiter: line 10 column 11 (char 357)"
Your JSON is not valid because you are missing a ]
character. Replace this line
[[{"name":"TEMP"},{"gpio":"4"},{"sensorType":"22"},{"temperatureLowLimit":"0"},{"temperatureHighLimit":"25"},{"temperatureThreshold":"5"},{"humidityLowLimit":"30"},{"humidityHighLimit":"60"},{"humidityThreshold":"10"}],
with this
[[{"name":"TEMP"},{"gpio":"4"},{"sensorType":"22"},{"temperatureLowLimit":"0"},{"temperatureHighLimit":"25"},{"temperatureThreshold":"5"},{"humidityLowLimit":"30"},{"humidityHighLimit":"60"},{"humidityThreshold":"10"}]],
A useful tool for the future, and the one that I used to check your problem is JSONlint.
JSONDecodeError: Expecting ',' delimiter: line 1 column 43 (char 42)
Your JSON is invalid, it has :
tokens in an array:
"result": ["0": "24", "1": "43", "2": "56"]
# ^ ^ ^
and
"result": ["0": "44", "1": "29", "2": "34"]
# ^ ^ ^
Fix your JSON input; either replace those colons with commas, remove the "0":
, "1":
, and "2":
'indices', or replace the [...]
array brackets with {...}
JSON object braces.
Related Topics
Python Selenium - Element Is Not Currently Interactable and May Not Be Manipulated
How to Reset Anaconda Root Environment
How to Get Max Output from a While Loop
Parentheses and Quotation Marks in Output
Filter All Rows That Do Not Contain Letters (Alpha) in 'Pandas'
How to Convert Data from Txt Files to Excel Files Using Python
How to Find a Word That Starts With a Specific Character
How to Use Chrome Webdriver in Selenium to Download Files in Python
How to Merge 2 CSV Files Together by Multiple Columns in Python
How to Retrieve SQL Result Column Value Using Column Name in Python
How to Find Duration Between Two Time Difference in Python Dataframe
Split/Explode a Column of Dictionaries into Separate Columns With Pandas
Python - Get Path of Root Project Structure
Calculating the Mean of Each Month by Year in Python
Could Not Translate Host Name "Db" to Address Using Postgres, Docker Compose and Psycopg2
How to Limit a Number to Be Within a Specified Range (Python)