Search code examples
pythonpython-jsonschema

Python Json Error , Expectiing comma delimitter


I tried many ways but not sure why this error coming. This is small script I am trying on SPYDER. Please help.

import json

myjson = '''
[
   "details":[
      {
         "MyTable":"NEWTABLE",
         "ReferTo":"Test"
      },
   ]
]
'''
data = json.loads(myjson)  

###  ABOVE LINE IS THROWING ERROR, --->  Expecting ',' delimiter


Solution

  • The data structure is incorrect. it should be a list of dict or a direct dict

    Ex:

    myjson = '''{
       "details":[
          {
             "MyTable":"NEWTABLE",
             "ReferTo":"Test"
          },
       ]
    }'''
    

    Or

    myjson = '''[
        {
        "details":[
            {
                "MyTable":"NEWTABLE",
                "ReferTo":"Test"
            },
        ]}
    ]'''
    
    import ast
    print(ast.literal_eval(myjson))