sirvon
sirvon

Reputation: 2615

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!

Upvotes: 1

Views: 104

Answers (1)

tknickman
tknickman

Reputation: 4621

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
      .....

Upvotes: 2

Related Questions