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)
0

3 Answers 3

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'))"
    }""")
Sign up to request clarification or add additional context in comments.

Comments

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\\"))"
     }""")

Comments

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"))'}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.