Python Forum
Get JSON Value based on Another value - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Get JSON Value based on Another value (/thread-32007.html)



Get JSON Value based on Another value - sambanerjee - Jan-14-2021

Hi -

This is the JSON below. I'm looking to get the value of 'bid' for each 'StockSymbol' - any help for this newbie ?

Output:
{ "currentPage":1, "trades":[ { "stockSymbol":"AAPL", "companyName":"Apple", "bid":130.17, "ask":133.42, "note":"None", "earningDueDate":"2021-01-27T00:00:00", "earningDueDateOption":0, "earningDueDateEstimated":false, "imageId":-1, "state":1, "isOptions":false, }, { "stockSymbol":"MTCH", "companyName":"Match Group", "bid":130.17, "ask":133.42, "note":"None", "earningDueDate":"2021-01-27T00:00:00", "earningDueDateOption":0, "earningDueDateEstimated":false, "imageId":-1, "state":1, "isOptions":false, }, ] }



RE: Get JSON Value based on Another value - buran - Jan-14-2021

for trade in data['trades']: print(f"{trade['stockSymbol']}: {trade['bid']}")
where data is JSON object, i.e. after you load the JSON string


RE: Get JSON Value based on Another value - sambanerjee - Jan-15-2021

(Jan-14-2021, 04:50 PM)buran Wrote:
for trade in data['trades']: print(f"{trade['stockSymbol']}: {trade['bid']}")
where data is JSON object, i.e. after you load the JSON string


Thank you - I'll try this out (I'm sure it will work) - I got by using the jmespath library -


This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.