I'm finding it difficult to turn a json like string into a json/dict object, I've got the data like this
{"key1":"value1","key2":[{"key2.1":"value2.1"},{"key2.2":"value2.2"}]}
When running type
on the variable it tells me it is of class str i.e <class 'str'>
. I need to get the string into a json or dict like format so I can extract all of the values named value...
I've tried json.loads
, json.load
, json.dumps
, ast.literal_eval
but nothing seems to be working. I've tried adding ['
and ']
either side of the string but still no luck. Any ideas? Thanks
EDIT:
I'm using a nodeJS backend sending a request to a flask server, the nodeJS axios request is this
get_values: (key_one, key_two) =>
axios.post('http://localhost:5000/example', {
key_one: key_one,
key_two: key_two
}).then(res => res.data),
on the flask side I'm doing this
@app.route('/example', methods=["POST","OPTIONS"])
def example():
convert_data = request.get_data()
string_data = convert_data.decode('utf8').replace("'", '"')
new_string = "'''" + string_data + "'''"
print(json.loads(new_string))
Then I get the an error