0
votes
try:
    os.mkdir('data')

except FileExistsError:

    os.chdir('data')

    data = {'teaminfo': []}

    data['teaminfo'].append({
        'managername': '',
        'teamname': '',
        'currentmoney': 100000
    })

    get_file_name()

    with open(filename, 'w') as outfile:
        json.dump(data, outfile, indent=4)


def submit():
    os.chdir('..')
    os.chdir('data')

    global filename

    print(filename)

    parsed = json.loads(filename)

    print(json.dumps(parsed, indent=4, sort_keys=True))


Error:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I would like to open the json file, and then edit "managername" and "teamname" with the input the user gives (haven't implemented it yet, because it cannot print the json by itself first).

The full error says that it happens at like 68, which is parsed = json.loads(filename).

1

1 Answers

0
votes

json.loads using for string parsing, if you need to read content of a file in json, you can use:

with open(filename) as json_file:
    parsed = json.load(json_file)

Documentation of json contains what is expected input for which method you want to use. See the link for more information.