I have a json string that I want to parse into a dictionary using the built in json
module. I'm able to do this using loads()
, as follows:
>>> j = '''{
... "first": 1,
... "second": "two",
... "third": {
... "first": "one",
... "second": null
... }
... }'''
>>> d = json.loads(j)
>>> pprint(d)
{u'first': 1,
u'second': u'two',
u'third': {u'first': u'one',
u'second': None}}
The issue is everything loads as a unicode
. Is there a way to force python to load everything as a string
instead? Alternatively, is there a simple way to do a deep convert once the dict
is created.
NOTE: Because I know people will ask, it is safe to assume that the keys and values I get will contain only ASCII characters and symbols, so I will not have a problem with special characters.