“Python Json Serialize Print Pretty” Kod odpowiedzi

Python Json Serialize Print Pretty

pretty_print_json = pprint.pformat(json_data).replace("'", '"')

with open('file_name.json', 'w') as f:
    f.write(pretty_print_json)
DreamCoder

Python Json Serialize Print Pretty

import json

def pp_json(json_thing, sort=True, indents=4):
    if type(json_thing) is str:
        print(json.dumps(json.loads(json_thing), sort_keys=sort, indent=indents))
    else:
        print(json.dumps(json_thing, sort_keys=sort, indent=indents))
    return None

pp_json(your_json_string_or_dict)
DreamCoder

Odpowiedzi podobne do “Python Json Serialize Print Pretty”

Pytania podobne do “Python Json Serialize Print Pretty”

Więcej pokrewnych odpowiedzi na “Python Json Serialize Print Pretty” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu