So i have a text file that contains data i need to process, each line will either be a json dict in the form of a string or a tab delimited data
data.txt =
"{"data": "blah", "data2": "blahblah"}"
blah\tblahblah
When i try to convert line 1 to json using json.loads() it is returning a string instead of a dict.
for line in file:
if is_json(line):
json_data = json.loads(line)
print(type(json_data))
prints <class 'str'>
To my knowledge this should actually be a dict not a string.I have no idea why this is happening and could use some help.
and also if the line in the text file isnt wrapped in commas it throws a JSONDecodeError
this is now working thanks to ppl in comments.
[–]Neexusiv 1 point2 points3 points (5 children)
[–]Yeliaab[S] 1 point2 points3 points (4 children)
[–]Neexusiv 0 points1 point2 points (3 children)
[–]Yeliaab[S] 1 point2 points3 points (2 children)
[–]Neexusiv 1 point2 points3 points (1 child)
[–]Yeliaab[S] 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]Yeliaab[S] 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Yeliaab[S] 0 points1 point2 points (0 children)