Search code examples
pythonjsonloopsin-place

How to add dictionary items to jsonarray while in loop?


So I have a data structure like so...a dictionary...

         fbIds = ["him", "her", "it", "that"]

then I have a database i'm adding a json structure to...

         res =  r.table("usa_nyc_bronx_merchants").insert({

                "street_address": streetName.lower(),
                "city": cityName.lower(),
                "state": stateName.lower(),
                "zipcode": zipcodeNumber.lower(),
                "county": countyName.lower(),
                "fbIds": [ADD DICTIONARY ITEMS TO THIS ARRAY]
          .....

How do i add the items in that dictionary into that that json array...mind you all this code is already in a for loop.

Thanks!


Solution

  • fbIds is already an array (list in python terms). So you should be able to just do:

    res =  r.table("usa_nyc_bronx_merchants").insert({
                "street_address": streetName.lower(),
                "city": cityName.lower(),
                "state": stateName.lower(),
                "zipcode": zipcodeNumber.lower(),
                "county": countyName.lower(),
                "fbIds": fbIds
          .....