[Python] python3 does not recognizes json

Discussão em 'Python' iniciado por Stack, Junho 24, 2025.

  1. Stack

    Stack Membro Participativo

    i am collecting json strings from several logs and append it to an list. then i iterate over the items in the list. Now the problem. the listentries are json but i am unable to convert it to list to work on the key value parts, its only string. Manually echoing the string into jq gives a valid json. Taking in ipython3 (on the same machine) the string into an variable, its a list wich i want.

    {
    "system_name": "orderxxx-live",
    "manifest_assets": [
    "xx-xxx",
    "xx-xx",
    "xx-xxx",
    "xx-xxx",
    "xx-xxx",
    "xx-xxx",
    "xx-xxx",
    "xx-xxx",
    "xx-xxx"
    ],
    "certificate_expiration_date": "2025-08-23 08:07:33",
    "artifacts": [
    {
    "artifact_name": "item-6.0.war",
    "artifact_version": "6.0.438"
    },
    {
    "artifact_name": "service-v1.0.war",
    "artifact_version": "2.0.10"
    },
    {
    "artifact_name": "camunda-webapp-ee-jboss-7.16.7-ee.war",
    "artifact_version": "7.16.7-ee"
    },
    {
    "artifact_name": "callback-v7.0.ear",
    "artifact_version": "1.0.56"
    }
    ],
    "application_server": [
    "postgres_dbms: localhost:5432/orderxxx?currentSchema=camunda",
    "applications_server: WildFly 34.0",
    "java_path: /usr/lib/jvm/temurin-11-jdk-amd64/bin/java"
    ],
    "additional_data": []
    }


    def __main__():
    sort_list = []

    ## extract data from logfiles
    for file_name in glob.glob(logstore_path + '/*/*/system/the_log.log'):
    with open(file_name, 'r') as ASS:
    for line in ASS:
    sort_list.append(line)

    sort_list = list(set(sort_list))
    for i in sort_list:
    print(type(i)) ## here only strings
    print(json.loads(i))

    ---
    Traceback (most recent call last):
    File "/home/druuhl/git/omdm_app_montool_apache/montool_vhost1/t_i_g/./tig_glue_data.py", line 41, in <module>
    __main__()
    ~~~~~~~~^^
    File "/home/druuhl/git/omdm_app_montool_apache/montool_vhost1/t_i_g/./tig_glue_data.py", line 30, in __main__
    ttt = json.loads(ttt)
    File "/usr/lib/python3.13/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^
    File "/usr/lib/python3.13/json/decoder.py", line 345, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3.13/json/decoder.py", line 363, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)



    any idea what wrong here, its not the first time i faced this issue.

    Continue reading...

Compartilhe esta Página