so I am trying to read a json file like this:
{
"Name": "hello",
"Source": " import json \n x= 10, .... "
}
the way I am trying to read it by using the json library in python thus my code looks something like this:
import json
input =''' {
"Name": "python code",
"Source": " import json \n x= 10, .... "
}'''
output = json.load(input)
print(output)
the problem that source has the invalid character "\n". I don't want to replace \n with \n as this is code will be later run in another program. I know that json.JSONDecoder is able to handle \n but I am not sure how to use.
\nis not invalid. It is a line feed.\nin a python string, because then it is escaped for python, but not for json. You need to write\\nin your string so that it is\nin the json.input = r''' {inputisn't valid json. If you want to copy your json file to a string, tryprint(repr(open('test.json').read()))and use that.