I have string representations of a dictionary like this:
s = "{'indexed': {'date-parts': [[2020, 9, 29]], 'date-time': '2020-09-29T19:03:40Z', 'timestamp': 1601406220500}}"
If I use json.loads(s)
to convert to dict
, I get an error as the value of date-parts
is a list
:
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-183-a61a3a11c21f> in <module>
----> 1 json.loads(v)
/opt/anaconda3/envs/work_area/lib/python3.7/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 parse_int is None and parse_float is None and
347 parse_constant is None and object_pairs_hook is None and not kw):
--> 348 return _default_decoder.decode(s)
349 if cls is None:
350 cls = JSONDecoder
/opt/anaconda3/envs/work_area/lib/python3.7/json/decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
/opt/anaconda3/envs/work_area/lib/python3.7/json/decoder.py in raw_decode(self, s, idx)
351 """
352 try:
--> 353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
355 raise JSONDecodeError("Expecting value", s, err.value) from None
JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
How do I solve this?