Question

Format a JSON attrbute using Python

  • 18 December 2015
  • 4 replies
  • 3 views

Userlevel 4
Badge +30

Hello Team,

I have a JSON attribute:

link: {"status": "OK", "results": [{"geometry": {"location_type": "RANGE_INTERPOLATED", "bounds": {"northeast": {"lat": -23.2186594, "lng": -45.9045073}, "southwest": {"lat": -23.2189106, "lng": -45.9060239}}, "viewport": {"northeast": {"lat": -23.2174360197085, "lng": -45.9039166197085}, "southwest": {"lat": -23.2201339802915, "lng": -45.9066145802915}}, "location": {"lat": -23.2186919, "lng": -45.9056747}}, "address_components": [{"long_name": "94-254", "types": ["street_number"], "short_name": "94-254"}, {"long_name": "Rua Benedito de Moura S\\u00e1", "types": ["route"], "short_name": "R. Benedito de Moura S\\u00e1"}, {"long_name": "Parque Residencial Aquarius", "types": ["sublocality_level_1", "sublocality", "political"], "short_name": "Parque Res. Aquarius"}]

My question: how can i formatte this attribute link with python?

I put the transformer JSONFlattener and works:

Thanks in Advance,


4 replies

Userlevel 4
Badge +25

Does this help: https://docs.python.org/2/library/json.html

Another option would be to have a JSONFlattener workspace and just run that with the Python script.

Userlevel 2
Badge +17

From the screenshot, I can see that a JSON document has been flattened properly, but the document you pasted is incomplete, so it doesn't help to consider a concrete solution.

The JSONFragmenter could be a quick solution. Required parameters setting is different depending on the structure of the actual JSON document and your desired result. This thread might be helpful: JSON Output Not Written

Userlevel 4
Badge +30

Does this help: https://docs.python.org/2/library/json.html

Another option would be to have a JSONFlattener workspace and just run that with the Python script.

Thanks @Mark2AtSafe . i will check this link

Userlevel 4
Badge +30

@takashi Thanks a lot!

Reply