Search code examples
pythonjsonpython-jsonschema

json.decoder.JSONDecodeError: Expecting value: , json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes:


Hi I am working with JSON in my file in Python:

import json
userData = '''[
{
    "userID" : "20",
    "devices" : {
        "360020000147343433313337" : "V33_03",
        "3f0026001747343438323536" : "Door_03",
        "170035001247343438323536" : "IR_06",
        "28004c000651353530373132" : "BED_17"
    }
},

]'''

info = json.loads(userData)

I get this error when I load it: json.decoder.JSONDecodeError: Expecting value:

or sometimes when I add something: json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes:


Solution

  • Try using the ast module

    Ex:

    import ast
    userData = '''[
    {
        "userID" : "20",
        "devices" : {
            "360020000147343433313337" : "V33_03",
            "3f0026001747343438323536" : "Door_03",
            "170035001247343438323536" : "IR_06",
            "28004c000651353530373132" : "BED_17"
        }
    },
    ]'''
    
    info = ast.literal_eval(userData)
    print(info)