0

I have a json (url = http://open.data.amsterdam.nl/ivv/parkeren/locaties.json) and I want to print all 'title', 'adres', 'postcode'. How can I do that?

I want to print it like this:

title.
adres.
postcode.

title. 
adres. 
postcode.

so among themselves

this is my python script

I hope you can help me with this

import urllib, json
url = "http://open.data.amsterdam.nl/ivv/parkeren/locaties.json"
import requests
search = requests.get(url).json()
print(search['title'])
print(search['adres'])
print(search['postcode'])

3
  • 1
    show your code as text Commented Nov 10, 2019 at 17:07
  • share your code, not picture Commented Nov 10, 2019 at 17:07
  • i have done it. Commented Nov 10, 2019 at 17:10

1 Answer 1

1

Using print(json.dumps(r, indent=4)) you can see that the structure is

{
    "parkeerlocaties": [
        {
            "parkeerlocatie": {
                "title": "Fietsenstalling Tolhuisplein",
                "Locatie": "{\"type\":\"Point\",\"coordinates\":[4.9032801,52.3824545]}",
                 ...
            }
        },
        {
            "parkeerlocatie": {
                "title": "Fietsenstalling Paradiso",
                "Locatie": "{\"type\":\"Point\",\"coordinates\":[4.8833735,52.3621851]}",
                 ...
            }
        },

So to access the inner properties, you need to follow the JSON path

import requests
url = ' http://open.data.amsterdam.nl/ivv/parkeren/locaties.json'
search = requests.get(url).json()
for parkeerlocatie in search["parkeerlocaties"]:
    content = parkeerlocatie['parkeerlocatie']
    print(content['title'])
    print(content['adres'])
    print(content['postcode'])
    print()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.