[Python] Python's orjson raised JSONDecodeError: str is not valid UTF-8

Discussão em 'Python' iniciado por Stack, Fevereiro 4, 2025.

  1. Stack

    Stack Membro Participativo

    I tried to load a .json file with standard JSON library. It works fine, but slowly:

    with open(file, 'r', encoding="utf-8") as jfile:
    lines = json.loads(jfile.read())


    I tried to use the orjson library, but the same code throws an error:


    JSONDecodeError: str is not valid UTF-8
    ​

    with open(file, 'r', encoding="utf-8") as jfile:
    lines = orjson.loads(jfile.read())


    How to handle this error?

    Continue reading...

Compartilhe esta Página