0

Can't solve how to convert JSON to python so that all data be in an array. I used code to extract JSON, but the problem is that to extract strings from each new JSON data set is a new issue due to the inequality of the number of columns.

import json
data = open('acndata_sessions.json')
json.load(data)

I also tried to use https://app.quicktype.io/, but the function result is:

data_from_dict(json.loads(json_string)) doesn't work.

Data set: json

4 Answers 4

0

This question seems to have been asked before. Convert JSON array to Python list

They use 'json.loads' instead of 'json.load' which you use. Both are functions, but they are different.

Sign up to request clarification or add additional context in comments.

1 Comment

This answer should be a flagged comment.
0

I think your looking for something like this.

import json
with open('myfile.json','r') as jsonFile:
            pythonJSON=json.load(jsonFile)
        jsonFile.close()
print(pythonJSON.keys())

The json.loads() is used when you have a string type. If the example above doesn't work with just json.load() try it with json.loads().

Comments

0

json.load already gives you a dictionary. You just have to use it and iterate through _items

import json
data = open('acndata_sessions.json')
data_dict = json.load(data)

# Load items from dictionary
items = data_dict['_items']

# Iterate in items
for item in items:
    # Print the item
    print(item)
    # Or if you want to further iterate on user inputs present in this item
    user_inputs = item['userInputs']
    # Check if there are any user inputs present in this item
    if user_inputs:
        for user_input in user_inputs:
            print(user_input)

Comments

0

Try checking this question. You can parse a json file like this:

import json

# read file
with open('example.json', 'r') as myfile:
    data=myfile.read()

# parse file
obj = json.loads(data)

# show values
print(str(obj['_items']))#returns a dict
print(str(obj['_meta']))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.