Skip to content

output_json

output_json

create_output_json(json_str)

Create an output JSON string by modifying the input JSON string.

The function removes the 'job_id' key from the input JSON and appends the modified JSON to a list. The keys in the modified JSON are transformed by removing underscores. Finally, the modified JSON is converted back to a JSON string and returned.

Parameters:

Name Type Description Default
json_str str

The input JSON string.

required

Returns:

Name Type Description
str

The output JSON string.

Source code in redesign_pipeline/flask_utils/output_json.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def create_output_json(json_str):
    """
    Create an output JSON string by modifying the input JSON string.

    The function removes the 'job_id' key from the input JSON and appends the modified
    JSON to a list. The keys in the modified JSON are transformed by removing underscores.
    Finally, the modified JSON is converted back to a JSON string and returned.

    Args:
        json_str (str): The input JSON string.

    Returns:
        str: The output JSON string.

    """

    data = []
    job_id = json_str['job_id']
    del json_str['job_id']
    data.append(json_str)
    for i in data:
        keys = list(i.keys())
        updated_keys = []
        for j in keys:
            new_key = ''.join(j.split('_'))
            updated_keys.append(new_key)
            i[new_key] = i.pop(j)
    output_dict = dict(job_id = job_id, data = data)
    output_json = json.dumps(output_dict)
    logger.debug(f'output_json, {output_json}')
    return output_json