0
with open ("xyz.json") as f:
    json_load=json.load(f)
    lis=["response.result.Potentials","response.result.Potentials.row",...........]

How to pass from list l1 to JSON object (getting the variable from list l1 and passing the variables JSON object).(IF we add anything to list and calls it should print json values).

print(data[l1[0]])

i want print from list l1 i.e print(data[response][result][Potentials])

print(data[l1[1]])

i.e print(data[response][result][Potentials][row]) in JSON format:

 {"response":
        {"result":
            {"Potentials":
                {"row":
                    [
                    {"no":"1","FL":
                        {"content":"523836000004148171","val":"POTENTIALID"}
                    },
                    {"no":"2","FL":
                        {"content":"523836000004924051","val":"POTENTIALID"}
                    },
                    {"no":"3","FL":
                        [
                        {"content":"523836000005318448","val":"POTENTIALID"},
                        {"content":"694275295","val":"Campaign Confirmation Number"}
                        ]
                    },
                    {"no":"4","FL":
                        [
                        {"content":"523836000005318662","val":"POTENTIALID"},
                        {"content":"729545274","val":"Campaign Confirmation Number"}
                        ]
                    },
                    {"no":"5","FL":
                        [
                        {"content":"523836000005318663","val":"POTENTIALID"},
                        {"content":"903187021","val":"Campaign Confirmation Number"}
                        ]
                    },
                    {"no":"6","FL":
                        {"content":"523836000005322387","val":"POTENTIALID"}
                    },
                    {"no":"7","FL":
                        [
                        {"content":"523836000005332558","val":"POTENTIALID"},
                        {"content":"729416761","val":"Campaign Confirmation Number"}
                        ]
                    }
                    ]
                }
            },
        "uri":"/crm/private/json/Potentials/getSearchRecords"}
    }
AvidLearner
  • 4,123
  • 5
  • 35
  • 48
Sh Ku
  • 45
  • 2
  • 6
  • Do I understand it correctly that the real question is: "How can I translate the string `"a.b.c"` into a lookup in a dictionary `d` as `d[a][b][c]`" ? – physicalattraction Jun 07 '15 at 09:39
  • 1
    Your list contains dictionary keys separated by `.` characters. Split each key by `.` (lis[0].split('.')`, and use the techniques in the dupe to traverse your dictionaries and retrieve each value: `getFromDict(json_load, lis[0].split('.'))` – Martijn Pieters Jun 07 '15 at 09:40

0 Answers0