There is a requirement that the JSON format data be displayed in the standard output of Python, and if the indentation display looks good on the data, there are many things to do with the JSON package
Import JSON
date = {u ' versions ': [{u ' status ': U ' current ', U ' id ': U ' v2.3 ', U ' links ': [{u ' href ': U ' http://controller : 9292/v2/', U ' rel ': U ' Self '}]}, {u ' status ': U ' supported ', U ' id ': U ' v2.2 ', U ' links ': [{u ' href ': U ' http://controller:9292 /v2/', U ' rel ': U ' Self '}]}, {u ' status ': U ' supported ', U ' id ': U ' v2.1 ', U ' links ': [{u ' href ': U ' http://controller:9292/v2/' , U ' rel ': U ' Self '}]}, {u ' status ': U ' supported ', U ' id ': U ' v2.0 ', U ' links ': [{u ' href ': U ' http://controller:9292/v2/', U ' rel ': U ' Self '}]}, {u ' status ': U ' supported ', U ' id ': U ' v1.1 ', U ' links ': [{u ' href ': U ' http://controller:9292/v1/', U ' rel ': U ' Self '}]}, {u ' status ': U ' supported ', U ' id ': U ' v1.0 ', U ' links ': [{u ' href ': U ' http://controller:9292/v1/', U ' rel ': U ' self '}]}
print json.dumps (data, Sort_keys=true, indent=2) # sorted and indented two characters output
This will produce the following output:
{"
versions": [
{
"id": "v2.3",
"links": [
{
"href": "http://controller:9292/v2/",
" Rel ":" Self "
}
],
" status ":" Current "
},
{
" id ":" v2.2 ",
" links ": [
{
] href ":" http://controller:9292/v2/","
rel ":" Self "
}
],
" status ":" Supported "
},
{
"id": "v2.1", "
links": [
{
"href": "http://controller:9292/v2/", "
rel": "Self"
}
],
"status": "Supported"
},
{
"id": "v2.0",
"links": [
{
"href": "http:// controller:9292/v2/",
" rel ":" Self "
}
],
" status ":" Supported "
},
{
" id ":" V1.1 ",
links": [
{
"href": "http://controller:9292/v1/",
"rel": "Self"
}
],
" Status ': ' Supported '
},
{
"id": "v1.0",
"links": [
{
"href": "http://controller:9292 /v1/",
" rel ":" Self "
}
],
" status ":" Supported "
}
]
}
As you can see, it's all formatted.
This is in Python, if you use the command line directly, you want to convert directly, you can use data | Python-mjson.tool to output JSON-formatted data
Echo ' {' First_key ': ' Value ', ' second_key ': ' value2 '} ' | Python-mjson.tool
For example, to filter the value of First_key to the command line directly, you can:
Echo ' {' First_key ': ' Value ', ' second_key ': ' value2 '} ' | Python-c ' Import sys, JSON; Print Json.load (Sys.stdin) [sys.argv[1]] ' First_key
You'll get the value for that.
The above is a small series for everyone to bring the data JSON format of the output of the example code all content, I hope that we support cloud Habitat Community ~