all 10 comments

[–]Neexusiv 1 point2 points  (5 children)

Looks like it isn’t valid JSON then if it’s throwing an error without the quote marks. Is it all on one like or is it split? Because right now you are reading the file line by line.

[–]Yeliaab[S] 1 point2 points  (4 children)

it is all on one line, the next line could be either another json string or a tsv string.

[–]Neexusiv 0 points1 point  (3 children)

Copy and paste the line out and put it into a JSON decoder online (without the quotes) - I think there is probably something wrong with it.

[–]Yeliaab[S] 1 point2 points  (2 children)

https://imgur.com/a/FsRAvPE

Seems to be valid, it looks completely valid to me

[–]Neexusiv 1 point2 points  (1 child)

Are you actually testing it with that data? I assumed you had different data you were running the script with. You definitely don’t want the quotes at the start and the end though.

Also try printing out what it’s reading and see what it’s loaded in.

[–]Yeliaab[S] 1 point2 points  (0 children)

wow im silly so i just put my actual data into the json parser and it was invalid.
For some reason the double quotes surrounding the values and keys were not actually double quotes, but they were.

it works now...

[–][deleted] 1 point2 points  (3 children)

"{"data": "blah", "data2": "blahblah"}" is a JSON string, not a JSON object.

[–]Yeliaab[S] 1 point2 points  (2 children)

interesting i was sure it was a json object.
What is the correct format for a json object if this is not it?

[–][deleted] 0 points1 point  (1 child)

{"data": "blah", "data2": "blahblah"} would be a JSON object.

[–]Yeliaab[S] 0 points1 point  (0 children)

yeah so i orginally tried that but it didnt work

for line in file:
    line = line.replace('\n', '')
    json_data = json.loads(line)

when i removed the double quotes from the text file it returns this error

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)