from dataframe to json

Viewed 56

Hi how are things? I have a dataframe, which looks like a recursive table, my idea is to be able to transform it to a json (in a mamushka way). Im using python

my example:

Datafame:

id name relations
1 config 0
2 buttons 1
3 accept 2
4 delete 2
5 descripton 1
6 title 1
7 juan 0

and the json that i whant is

[{
"id":"1"
"name":"config",
"relations":
  [{
    "id":"2"
    "name":"buttons"
    "relations":[{
        "id":"3"
        "name":"accept"
         },
        {
         "id":"4",
        "name":"delete"
        }],
    },
   {
   "id":"5"
    "name":"descripton",
    "relations":[]
   },
   "id":"6"
   "name":"title",
   "relations":[]
  }],
"id":"7",
"name":"juan",
"relations":[] 
}]

As you will see, in the column "relation", you can see that it joins with its parents (id)

0 Answers
Related