in Education by
This my my JSON: { "maps": [ { "id": "AT", "iscategorical": "0" }, { "id": "AT", "iscategorical": "0" } ], "masks": [ "id": "Jaipur" ], "om_points": "Outcome", "parameters": [ "id": "Jaipur" ] } To print the JSON data I wrote this: import json from pprint import pprint with open('data.json') as f: data = json.load(f) pprint(data) but I faced an exception raised by the program: Traceback (most recent call last): File "", line 5, in data = json.load(f) File "/usr/lib/python3.5/json/__init__.py", line 319, in loads return _default_decoder.decode(s) File "/usr/lib/python3.5/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.5/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting ',' delimiter: line 13 column 13 (char 213) I want to parse the JSON and extract the values, How can I do it? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
The data you are using is not valid JSON format, You should use { } instead [ ] : [ ] is for JSON arrays, and it's used for list in Python. whereas { } is for for JSON objects, and it's used for dict in Python. This is what you can use: { "maps": [ { "id": "AT", "iscategorical": "0" }, { "id": "AT", "iscategorical": "0" } ], "masks": { "id": "Jaipur" }, "om_points": "output", "parameters": { "id": "Jaipur" } } so you can use this code: import json from pprint import pprint with open('data.json') as d: data = json.load(d) pprint(data) Using this data you can also find values like: data["maps"][0]["id"] data["masks"]["id"] data["om_points"] Try these codes and if you have any doubts you can ask them in comments.

Related questions

0 votes
    How can someone parse a numeric string like "121.5555" to it's corresponding float value 121.5555? or parse a ... str to an int. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    In java, how can I parse json text to get value of variables like post_id ? Here is my json text { "page": { ... ": "1234567890" } ] } Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    Why can't we Python parse this JSON data?...
asked Jan 11, 2021 by JackTerrance
0 votes
    I want to parse a .json column through Power BI. I have imported the data directly from the server and ... simplified parsed columns. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I have a basic dict as follows: sample = {} sample['title'] = "String" sample['somedate'] = somedatetimehere When ... 21:46:24.862000. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I am confused about the usage of string.join(list) instead of list.join(string), for instance see this code: ... reason behind this? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    What makes using range() to make the process of generating a quadrillion values in a instant of time, I am amazed by ... o += 1 return Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I have json file as follows: { "status":"UP", "diskSpace": {"status":"UP","total":63279460352," ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    I want to write a program which returns different values for different input,it can be easily done using switch ... some alternative? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    How can I convert a str from uppercase, or half uppercase to lowercase? E.x. "Decimeter" to "decimeter" Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    How can I get the number of elements of a list? Ex- items = [] items.append("one") items.append("two") items.append("three") Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I am a learner and just want to know the basic concept of super(). Here in the given code I want to know ... () ChildOne() ChildTwo() Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I want to freeze the dos pop-up, I already tried raw-input as mentioned in my study material of Python 2.6 and ... (3**200) raw_input() Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    In a list with range(1,16) and I am trying to divide this list in some fixed numbe n . Let's assume n=7 ... uneven, How can I do that? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I want to use python to connect to a MySQL database, how can I do that? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
...