How to convert jsonl to json in python

Issue

This Content is from Stack Overflow. Question asked by Luca Berhard

I am looking for a way to convert a JSONL file to JSON.

I have written a python program but at some point it’s just getting to slow because the JSON file gets to big. And with every loop I checked if the keys are in thereā€¦

Maybe some of you has an idea on how to write a program that does the following:
The JSONL file is from a Firebase export, which looks like this:
{"__path__":"cars/89dHLbXAOooudSNHv6Jt","__exportPath__":"","__id__":"89dHLbXAOooudSNHv6Jt","brandId":"Fp5Kwr7NXNRPxY7Yx3QK","name":"Testuser", "email": "test.user@email.com", "settings":{"test1":true,"test2":true}}

The document can also have subcollections:
{"__path__":"cars/89dHLbXAOooudSNHv6Jt/subcollection/dwadwadawdwaddwa","__exportPath__":"","__id__":"dwadwadawdwaddwa","modelId":"d54321242","name":"testcar", "motor": "example f1"

this needs to be converted into this:

    {
        "cars": {
            "89dHLbXAOooudSNHv6Jt": {
                "brandId": "Fp5Kwr7NXNRPxY7Yx3QK",
                "name": "Testcar",
                "email": "test.user@email.com",
                "settings": {
                    "test1": true,
                    "test2": true
                },
                "subcollection": {
                    "dwadwadawdwaddwa": {
                        "modelId": "d54321242",
                        "name": "testcar",
                        "motor": "example f1"
                    }
                }
            }
        }
    }



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?