Parsing Firebase JSON with Python

蓝咒 提交于 2020-01-03 04:52:06

问题


I'm working with the following JSON structures

{
    "-L6Tr0Wl5fuG3tDgUPCa": {
        "List": "{'x': [0.02245, 0.02196], 'y': [0.96941, 0.97014], 'z': [0.05344, 0.05368]}",
        "Index": "17361"
    },
    "-L6Tr4j05NV6BJKcaRSe": {
        "List": "{'x': [0.03196, 0.01537], 'y': [0.96795, 0.96966], 'z': [0.05051, 0.04929]}",
        "Index": "17362"
    }
}

The name of each entry is random (e.g. L6Tr0Wl5fuG3tDgUPCa) that is generated by firebase whenever we push a new entry. What is the best way to parse and iterate through each entry of such a JSON file in python?

The file is huge with a couple of thousands of such entries.


回答1:


I've never done Python before, but this seems to work in https://www.python.org/shell/:

import json
data = {
    "-L6Tr0Wl5fuG3tDgUPCa": {
        "List": "{'x': [0.02245, 0.02196], 'y': [0.96941, 0.97014], 'z': [0.05344, 0.05368]}",
        "Index": "17361"
    },
    "-L6Tr4j05NV6BJKcaRSe": {
        "List": "{'x': [0.03196, 0.01537], 'y': [0.96795, 0.96966], 'z': [0.05051, 0.04929]}",
        "Index": "17362"
    }
}

for key in data:
  print(key, data[key])

Also see:

  • How can I loop over entries in JSON?


来源:https://stackoverflow.com/questions/49095497/parsing-firebase-json-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!