halconnen
halconnen

Reputation: 99

Parse JSON with Python

I'd like to parse

{"ticker":{"high":31.9099,"low":22.5,"vol":108468,"buy":29.61,"sell":30,"last":29.61}}

and end up with:

last = 29.61

but I don't know where to start parsing python :(

Upvotes: 2

Views: 3590

Answers (2)

Helen Neely
Helen Neely

Reputation: 4740

I'm not sure, but I thought I should post this here in case someone else finds it useful. There is a nice post here on Parsing JSON in Python - it is small be shows how you could use it in different scenarios.

Good luck!

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799240

>>> text = '''{"ticker":{"high":31.9099,"low":22.5,"vol":108468,"buy":29.61,"sell":30,"last":29.61}}'''
>>> json.loads(text)
{u'ticker': {u'sell': 30, u'buy': 29.609999999999999, u'last': 29.609999999999999, u'vol': 108468, u'high': 31.9099, u'low': 22.5}}
>>> json.loads(text)[u'ticker'][u'last']
29.609999999999999

Or use simplejson with older versions of Python.

Upvotes: 13

Related Questions