A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Sort JSON keys in and write them into a file using python programming
Q:

Sort JSON keys in and write them into a file using python programming

0

Sort JSON keys in and write them into a file

Sort following JSON data alphabetical order of keys

sampleJson = {"id" : 1, "name" : "value2", "age" : 29}

Expected Output:

{
    "age": 29,
    "id": 1,
    "name": "value2"
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import json

sampleJson = {"id" : 1, "name" : "value2", "age" : 29}

print("Started writing JSON data into a file")
with open("sampleJson.json", "w") as write_file:
    json.dump(sampleJson, write_file, indent=4, sort_keys=True)
print("Done writing JSON data into a file")

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now