How to keep following records in json format

hi, we need to keep some related record in json.

ex set1
level1, level2 , level3 (this can be n numbers), weitage9in percent)
a , null ,null, 10 (here “a” is at first level has weitage10)
a ,b, null, 20 (“b” is inside “a” and got weitage 20)
a ,b, c, 5(“c” is inside “b” and got weithage 5)
a ,b, d, 8 (“d” is inside “b” and got weithage8)
ax ,null, null, 3(here “ax” is at first level has weitage10)
ax ,b, null, 8(same as above)
ax ,b, c, 9(same as above)
–so level1 will be unique but it will repeat if it has got any one inside it.
so uniqueness of the record is no of levels.
so there uniquness is on
level1.level2,level3

ex set2
level1,level2,level3 level4,weitage
axx ,null, null, null, 3(here “ax” is at first level has weitage10)
axx ,b, null, null,8(same as top most ex set)
axx ,b, c, null,9(same as top most ex set)
axx ,b, c,d,10(same as top most ex set)
the leaf node could be many but uniques , so there uniquness is on
level1.level2,level3,leve4

and both ex set1 and ex set2 can come together.

now requirement is we should be able to traverse from each leaf node to topmost node.and vise versa uniquly.

so please suggest that how we should keep these tow bunch where level can increase at any time in json.