I am using python 3.10.4. I have a string which is as follows:
str_obj = "[(190229461780583, 'main'), (302030571463836, 'feature/BRANCH_livestream'), (1071064128966159, 'feature/BRANCH_sensitive'), (1137211553786277, 'main'), (1283366887974580, 'feature/add_sql_vm'), (1492751472739439, 'feature/BRANCH-2977'), (2662272892040840, 'main'), (4078787696930326, 'main')]"
I need to convert it to a json object. I need it in json format for further data extraction. Following this link I used json.loads() to convert it from string to json:
json_obj = json.loads(str_obj)
However I am getting the error:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I checked this link but it is not really related to my problem.
I cannot simply drop "" from str_obj as this is the value I am receiving from an environment variable sent to me from a DevOps pipeline.
I would like to know what the root cause problem is and how I can resolve it.
line 1 column 2, notline 1 column 1. It happens because the string is not valid JSON. Please make sure you know the JSON specification. It is not the same as Python syntax. "I cannot simply drop "" from str_obj" In the code that you show,str_objdoes not have quotation marks surrounding it - that's part of the Python syntax to indicate that you have a string, not part of the string contents.json.dumps, orjson.dumpif you have a stream to feed it to directly). If you are receiving this data as described, that implies that it was converted to string viastr. While it's possible to work with such data, it's not the Web standard and it isn't JSON..dumpscreates a string;.dumpwrites directly to a stream - which some web APIs might offer you. "It seems that this is still not valid json. Isn't it?" It is not the usual way of using JSON, but it is entirely valid JSON. Again, please read the spec.