Load JSON object including escaped json string
Question: I'm trying to load a JSON object from a string (via Python). This object has a
single key mapped to an array. The array includes a single value which is
another serialized JSON object. I have tried a few online JSON parsers /
validators, but can't seem to identify what the issue with loading this object
is.

JSON Data:

    
    
        {
          "parent": [
            "{\"key\":\"value\"}"
          ]
        }
    

Trying to load from Python:

    
    
    >>> import json
    >>> test_string = '{"parent":["{\"key\":\"value\"}"]}'
    >>> json.loads(test_string)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
        return _default_decoder.decode(s)
      File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
        obj, end = self.scan_once(s, idx)
    ValueError: Expecting , delimiter: line 1 column 15 (char 14)
    


Answer: If you try out your string in the REPL, you'll see pretty quickly why it
doesn't work:

    
    
    >>> '{"parent":["{\"key\":\"value\"}"]}'
    '{"parent":["{"key":"value"}"]}'
    

Notice the `\` have gone away because python is treating them as escape
sequences ...

One easy fix is to use a raw string:

    
    
    >>> r'{"parent":["{\"key\":\"value\"}"]}'
    '{"parent":["{\\"key\\":\\"value\\"}"]}'
    

e.g.

    
    
    >>> import json
    >>> test_string = r'{"parent":["{\"key\":\"value\"}"]}'
    >>> json.loads(test_string)
    {u'parent': [u'{"key":"value"}']}
    

