0

I have an output somewhat of the form below. How do I turn it into a dictionary or pandas indexed 2D array?

'{"key1":true,"key2":[1,1,1],"key3":[[["name1",0],["name2",0]],[[1,0][1,0][1,0]]}'
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786

2 Answers2

1

You can try this:

import ast
s = '{"key1":true,"key2":[1,1,1],"key3":[[["name1",0],["name2",0]],[[1,0],[1,0],[1,0]]}'
final_data = ast.literal_eval(s)
Ajax1234
  • 69,937
  • 8
  • 61
  • 102
0

There are missing commas in the last value.

[[1,0][1,0][1,0]]]}'

This should be:

[[1,0],[1,0],[1,0]]]}'

When fixed, you get:

>>> import json
>>> foo = '{"key1":true,"key2":[1,1,1],"key3":[[["name1",0],["name2",0]],[[1,0],[1,0],[1,0]]]}'
>>> json.loads(foo)
{u'key3': [[[u'name1', 0], [u'name2', 0]], [[1, 0], [1, 0], [1, 0]]], u'key2': [1, 1, 1], u'key1': True}
>>>
Sharad
  • 9,282
  • 3
  • 19
  • 36