Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
61 views
in Technique[技术] by (71.8m points)

python - Save JSON data in Firebase

I got the following json data to save it in

   {
    "ACCIONA": {
        "ultimo": 126.1,
        "%dif": 5.52,
        "max": 126.5,
        "min": 119.8,
        "volumen": "174305",
        "efectivo": 21710.34,
        "fecha": "07/01/2021",
        "hora": "Cierre"
    },
    "ACERINOX": {
        "ultimo": 9.82,
        "%dif": 2.96,
        "max": 9.84,
        "min": 9.55,
        "volumen": "1132608",
        "efectivo": 10998.42,
        "fecha": "07/01/2021",
        "hora": "Cierre"
    }
}

if I import this data manually to firebase it works perfectly. But if I try to save it with python like this

 ref = db.reference('/')

empresasJson = json.dumps(empresasDict, ensure_ascii=True)

ref.set(empresasJson)

It saves the entire json as one line instead of saving it with childs

question from:https://stackoverflow.com/questions/65617516/save-json-data-in-firebase

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Maybe you can try to do this.

ref.set(empresasDict)

Based on documentation, it seems that you don't need to serialize your data. So the json.dumps is unnecessary

https://firebase.google.com/docs/database/admin/save-data#python


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...