0

I have a problem loading the following using json.loads()

json.loads("""{"columnName": "ML_Status_Flags_1.LAST_RESOLVED_DATE",
      "columnId": "3",
      "columnIndex": 5, 
      "formulaString": "\u003dGROUPBY(ASdate(Formatdate(#Remedy_CL_!LAST_RESOLVED_DATE_ML_Status_Flags_1;\"dd-MM-yyyy\");\"dd-MM-yyyy\"))"
    }""")

I got the following errors

ERROR:root:An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line string', (1, 9))

and At the end of the error I get this

JSONDecodeError: Expecting ',' delimiter: line 4 column 106 (char 215)

3 Answers3

2

swap your double quotes for singles on the dates, I dont believe they are escaped with \ in a string

json.loads("""{"columnName": "ML_Status_Flags_1.LAST_RESOLVED_DATE",
      "columnId": "3",
      "columnIndex": 5, 
      "formulaString": "\u003dGROUPBY(ASdate(Formatdate(#Remedy_CL_!LAST_RESOLVED_DATE_ML_Status_Flags_1;'dd-MM-yyyy');'dd-MM-yyyy'))"
    }""")
AlexW
  • 2,843
  • 12
  • 74
  • 156
1

You need to escape your double quotes with a double backward slash \\:

json.loads("""{"columnName": "ML_Status_Flags_1.LAST_RESOLVED_DATE",
       "columnId": "3",
       "columnIndex": 5,
       "formulaString": "\u003dGROUPBY(ASdate(Formatdate(#Remedy_CL_!LAST_RESOLVED_DATE_ML_Status_Flags_1;\\"dd- MM-yyyy\\");\\"dd-MM-yyyy\\"))"
     }""")
1

Looks like a valid json. Adding 'r' before does the trick. See here for more info about 'r' and 'u': https://stackoverflow.com/a/2081708/7386332

The reason is that \ is an escape character in Python and r' makes sure does are not taken into consideration.

import json

json.loads(r"""{"columnName": "ML_Status_Flags_1.LAST_RESOLVED_DATE",
      "columnId": "3",
      "columnIndex": 5, 
      "formulaString": "\u003dGROUPBY(ASdate(Formatdate(#Remedy_CL_!LAST_RESOLVED_DATE_ML_Status_Flags_1;\"dd-MM-yyyy\");\"dd-MM-yyyy\"))"
    }""")

Returns

{'columnId': '3',
 'columnIndex': 5,
 'columnName': 'ML_Status_Flags_1.LAST_RESOLVED_DATE',
 'formulaString': '=GROUPBY(ASdate(Formatdate(#Remedy_CL_!LAST_RESOLVED_DATE_ML_Status_Flags_1;"dd-MM-yyyy");"dd-MM-yyyy"))'}
Anton vBR
  • 18,287
  • 5
  • 40
  • 46