Skip to content
Advertisement

How to search a dictionary and append a field to JSON by key value?

I am trying to write a script like this in Python:

Let’s say I have two JSON files, one has a data structure like this :

fruitswithprice.json

JavaScript

the other is fruitsnoprice.json

JavaScript

I want to append the price field to fruitsnoprice.json for every entry that the key “fruit” matches.

I tried this :

JavaScript

getting an error at wInList[‘price’] == word[‘price’].

Advertisement

Answer

You can’t do this: wInList['price'] == word['price'].

You can assign it like this:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement