0
votes

When I try to use json.loads on this string in Python, I get the following error.

I don't understand why because I believe I am formatting the string correctly for JSON.

Code example below creates the following error: json.decoder.JSONDecodeError: Extra data: line 1 column 132 (char 131)

import pymongo

import json

mongo_import_str = '{"Top_Level": {"NextLevelDown": {"First": "1","Second":"2","Third":"3"}}, "NextLevelDown2": {"First":"1","Second":"2","Third":"3"}}}'

mongo_import = json.loads(mongo_import_str) collection.insert_one(mongo_import)

1
Forgot to include the line of code that is causing the error:) This should have been just before the collection.insert_one(). mongo_import = json.loads(mongo_import_str)Robert Sparks
Please edit your post so as to make it complete. See: How to create a Minimal, Reproducible Examplenyedidikeke

1 Answers

0
votes

Here's how the JSON looks with some better formatting.

{
    "Top_Level":{
        "NextLevelDown":{
            "First": "1","Second":"2","Third":"3"
        }
    },
    "NextLevelDown2":{
        "First":"1","Second":"2","Third":"3"
    }
}
}

As you can see, there's a spare } in there. Remove it.