0

I have got something like this

sample.jpg

photos/sample1.jpg

photos/2006/sample2.jpg

photos/2007//sample3.jpg

and I want to get this in a hierarchy in JSON object as a list if its a file then it will be only object and if it is a folder then it will be list of object again.

Basically I want this in an JSON object like this..

{
  [
    {
      type: folder
      name: photos
      children: [
        {
          type: folder
          name: 2006
          children : [
            {
              type: file
              name: sample2.jpg
            }
          ]
        }
        {
          type: folder
          name: 2007
          children : [
            {
              type: file
              name: sample3.jpg
            }
          ]
        }
        {
          type : file
          name : sample2.jpg
        }
      ]
    }
    {
       type: file
       name: sample.jpg
    }
  ]
}

Is it possible to get like this ? I'm not able to get an idea about how to do this .

ankur suman
  • 151
  • 1
  • 3
  • 10
  • 1
    stackoverflow is not a code writing service. Show something you have tried when you are asking a question. – deadshot Jan 15 '21 at 09:32
  • Also I have the list of the files to start with so I cannot use os.walk as in above solution – ankur suman Jan 15 '21 at 10:21
  • you don't need to use the same solution you can use it as reference and try something if you stuck somewhere someone can help you. and onething if you want an idea stackoverflow is not the site – deadshot Jan 15 '21 at 11:28

0 Answers0