0

I have a JSON String like this:

{
  "Sommersprossen": {
    "count": 5,
    "lastSeenTime": 1586959168567
  },
  "inkognito": {
    "count": 7,
    "lastSeenTime": 1586901586361
  },
  "Marienkäfer": {
    "count": 7,
    "lastSeenTime": 1586958264090,
    "difficulty": 0.8902439024390244,
    "difficultyWeight": 82
  },
  "Zaun": {
    "count": 8,
    "lastSeenTime": 1586958848320
  },

Now I want to print something like this: Sommersprossen, inkognito, Marienkäfer, Zaun.
But I don't know how to... My existing Python code is:

url = "https://skribbliohints.github.io/German.json"

response = urllib.request.urlopen(url)

data = json.loads(response.read())

But the problem is I cant find a way to print the objects names.

3 Answers3

1

A json is essentially just a dictionary. You can access it like any other python dictionary.

url = "https://skribbliohints.github.io/German.json"

response = urllib.request.urlopen(url)

data = json.loads(response.read())

roots = list(data.keys())
goalie1998
  • 1,427
  • 1
  • 9
  • 16
0

You can treat this json output as dictionary and print its Keys, for this exapmle you can simply perform it with:

data.keys()

Output:

dict_keys(['Sommersprossen', 'inkognito', 'Marienkäfer', 'Zaun'])
Celius Stingher
  • 17,835
  • 6
  • 23
  • 53
0

It’s a dict, so you can do:

“, “.join(data.keys())
friedcell
  • 150
  • 6