M
M
Mikhail Frolov2021-08-07 20:10:02
Algorithms
Mikhail Frolov, 2021-08-07 20:10:02

How to bypass a dictionary with an array inside?

Question in the subject, in principle. The strange structure of statham. There is a dictionary in the dictionary, and in it an array with dictionaries, the roof goes.

{
  "folder": [
    {
      "file": [
        {
          "path": "fae3c54eb95cdd24aafb3837f25530cd/asset",
          "mime-type": "application/octet-stream",
          "size": 4892,
          "name": "asset"
        },
        {
          "path": "fae3c54eb95cdd24aafb3837f25530cd/preview.png",
          "mime-type": "image/png",
          "viewable": 1,
          "size": 5733,
          "name": "preview.png"
        }
      ],
      "name": "fae3c54eb95cdd24aafb3837f25530cd",
      "path": "undefined"
    },
    {
      "file": [
        {
          "path": "fdfa6ff90c30bb94f8500ed681f582cf/asset",
          "mime-type": "application/octet-stream",
          "size": 4912,
          "name": "asset"
        },
        {
          "path": "fdfa6ff90c30bb94f8500ed681f582cf/preview.png",
          "mime-type": "image/png",
          "viewable": 1,
          "size": 20010,
          "name": "preview.png"
        }
      ],
      "name": "fdfa6ff90c30bb94f8500ed681f582cf",
      "path": "undefined"
    }
  ],
  "file": [
    {
      "path": ".icon.png",
      "mime-type": "image/png",
      "viewable": 1,
      "size": 26899,
      "name": ".icon.png"
    }
  ]
}


Is there any generic workaround? I intend to make a tree of html elements from json, folders with files attached to them, etc. A question for veterans rather, someone must have come across this. I don’t ask you to write code for me, suggest me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Frolov, 2021-08-07
@neuralink7232050

My attempt to deduce keys recursively

def Recurse(arraydict):
  # массив словарей
  for i in arraydict:
        for key_dict in i.keys():
            print(key_dict)
            if type(i[key_dict]) == list:
                Recurse(i[key_dict])
data = 'json, который выложил выше'
Recurse([data])

I'm a good guy in short

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question