import json
array = '{"fruits": ["apple", "banana", "orange"]}'
data = json.loads(array)
That is my JSON array, but I would want to convert all the values in the fruits string to a Python list. What would be the correct way of doing this?
data will return you a string representation of a list, but it is actually still a string. Just check the type of data with type(data). That means if you try using indexing on this string representation of a list as such data['fruits'][0], it will return you "[" as it is the first character of data['fruits']
You can do json.loads(data['fruits']) to convert it back to a Python list so that you can interact with regular list indexing. There are 2 other ways you can convert it back to a Python list suggested here
data['fruits']will be a list - jdilist. A JSON Object is homologous to a Pythondict. Technically, you have adictcontaining a single key-value pair where the value is alistof strings. - Joel Cornett