0

Is there a way we can convert JSON output to python code, any online tool available?

I have a JSON output as below, I need to fetch clientHostname, completionTime, creationTime in a table format.

'{"backups":[{"attributes":[{"key":"*backup start time","values":["1587952891"]},{"key":"*policy action name","values":["Server db backup: 1587952891"]},{"key":"*policy name","values":["Server Protection: 1587952891"]},{"key":"*policy protection period","values":["0: 1587952891"]},{"key":"*policy workflow name","values":["Server backup: 1587952891"]},{"key":"*ss clone retention","values":["          15879891:          1587952891:   1864708"]},{"key":"group","values":["Server Protection"]},{"key":"saveset features","values":["CLIENT_SAVETIME"]}],"browseTime":"2020-05-18T10:01:31+08:00","clientHostname":"server.com","clientId":"52d7aefe-0005f9c1","completionTime":"2020-04-27T10:01:35+08:00","creationTime":"2020-04-27T10:01:31+08:00","fileCount":338,"id":"4d8eda0-0425f9c1","instances":[{"clone":false,"id":"1587952891","status":"Recoverable","volumeIds":["446929344"]}],"level":"Full","links":[{"href":"https://server:9090/nwrestapi/v3/global/backups/4d8ed5f6-00000006-3ea63cfb-5ea63cfb-03c3d3a0-0425f9c1","rel":"item"}],"name":"bootstrap","retentionTime":"2020-05-18T23:59:59+08:00","saveTime":"2020-04-27T10:01:31+08:00","shortId":"1051081979","size":{"unit":"Byte","value":14649768},"type":"File"},{"attributes":[{"key":"*anchor save set time","values":["1585706553"]}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Ashish
  • 47
  • 5

1 Answers1

1

I'm not 100% sure what your question is so I'm assuming you have some JSON object in your python code stored as a string and you want to parse it into Python objects. Python has a built in library called "json". This allows you to convert a JSON object into a Python dictionary that you can access from there.

This is a good overview of the library: https://www.w3schools.com/python/python_json.asp

import json

# some JSON:
x =  '{ "name":"John", "age":30, "city":"New York"}'

# parse x:
y = json.loads(x)

# the result is a Python dictionary:
print(y["age"])
  • I have modified the question, could you please help fetching the required field from the json output. – Ashish Apr 27 '20 at 16:06