0

I have a folder that contains many JSON files. I want to write Python code that scans all files, reads them, and merges them into a single list object.

I tried the following.

mypath = 'C:/Users/data'
files = ['f1.josn', 'f2.josn', ..., 'f20.josn']
output_list = []
for file in files:
    with open(mypath+'/'+file, encoding='utf-8') as infile:
        output_list.append(json.load(infile))

I got a traceback after running the above code:

JSONDecodeError: Invalid control character at: line 1002 column 99 (char 38611)

1 Answer 1

1

The problem is in one (or all) of the json-files. Quoting this page:

If the data being deserialized is not a valid JSON document, a JSONDecodeError will be raised.

Sign up to request clarification or add additional context in comments.

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.