praba karan
praba karan

Reputation: 21

how to Converting below json and load into json.loads()?

While loading below json into json.loads(), I get error on "value" as it does not contain "".

jstring = '{"ABC": {value: "2787456", basevalue: "34453176"}}'

Upvotes: 0

Views: 167

Answers (2)

bagrat
bagrat

Reputation: 7418

The problem is that value must also be enclosed in quote marks like this "value", in order to be parsed as json key.

jstring = '{"ABC": {"value": "2787456", "base value": "34453176"}}'

Upvotes: 0

Simeon Visser
Simeon Visser

Reputation: 122336

Keys need to be enclosed in double quotes:

>>> jstring='{"ABC":{"value":"2787456","basevalue":"34453176"}}'
>>> import json
>>> json.loads(jstring)
{u'ABC': {u'value': u'2787456', u'basevalue': u'34453176'}}

Upvotes: 2

Related Questions