How to parse (and split into multiple small json files for all children) a very Big Nested Json with its relation tree to all the deep level nodes with index in case of Array without any hard coding of Tags. Below is the Input and Expected Output Json

INPUT JSON :

{
“Start”:{
“HInfo”:{
“HInfoID”:“ABCD1234”,
“SUType”:“OnStup”,
“SModel”:“Test”,
“Hostname”:“Dummy”,
“SType”:“Laptop”,
“Monitor”:{
“HInfoID”:“ABCD1234”,
“Index”:0,
“Type”:“Lenovo”,
“VSData”:“XYZVN”
},
“OS”:“MSW-07”,
“LRTime”:“2017-05-04”,
“Cables”:[
{
“HInfoID”:“ABCD1234”,
“Index”:0,
“Name”:“LC”,
“Status”:“Installed”
},
{
“HInfoID”:“ABCD1234”,
“Index”:1,
“Name”:“WLSwitch”,
“Status”:“Off”
},
{
“HInfoID”:“ABCD1234”,
“Index”:2,
“Name”:“WLAN”,
“Status”:“Installed”
}
],
“NFan”:{
“HInfoID”:“ABCD1234”,
“Index”:0
},
“Disk”:[
{
“HInfoID”:“ABCD1234”,
“Index”:0,
“Name”:“DISK0”,
“MKMdl”:“THB”,
“BW_MB”:694,
“Partition”:[
{
“HInfoID”:“6ABCD1234”,
“DGID”:“ABCD1234”,
“Index”:0,
“Name”:“Not Used”,
“SM”:500
},
{
“HInfoID”:“ABCD1234”,
“DGID”:“ABCD1234”,
“Index”:1,
“Name”:“C:”,
“SM”:476438
}
]
},
{
“HInfoID”:“ABCD1234”,
“Index”:1,
“Name”:“DISK1”,
“MKMdl”:“JFlsh”,
“BW_MB”:0,
“Partition”:{
“HInfoID”:“ABCD1234”,
“DGID”:“ABCD1234”,
“Index”:0,
“Name”:“E:”,
“SM”:7727
}
}
]
}
}
}

Expected Output JSON Files :

  1. { “obj_class”:“HInfo”, “obj_instance”:“HInfo”, “relation_tree”:“Start.HInfo”, “HInfo”:{ “HInfoID”: “ABCD1234”, “SUType”:“OnStup”, “SModel”:“Test”, “Hostname”:“Dummy”, “SType”:“Laptop”, “OS”:“MSW-07”, “LRTime”:“2017-05-04” }}
  2. { “obj_class”:“Monitor”, “obj_instance”:“Monitor-1”, “relation_tree”:“Start.HInfo.Monitor.Monitor-1”, //This Monitor-1 indicates that Monitor has only 1 instance “Monitor”:{ “HInfoID”:“ABCD1234”, “Index”:“0”, “Type”:“Lenovo”, “VSData”: “XYZVN” }}
  3. { “obj_class”:“Cables”, “obj_instance”:“Cables-1”, “relation_tree”:“Start.HInfo.Cables.Cables-1”,
    “Cables”:{ “HInfoID”: “ABCD1234”, “Index”:“0”, “Name”:“LC”, “Status”:“Installed” }}
  4. { “obj_class”:“Cables”, “obj_instance”:“Cables-2”, “relation_tree”:“Start.HInfo.Cables.Cables-2”,
    “Cables”:{ “HInfoID”: “ABCD1234”, “Index”:“1”, “Name”:“WLSwitch”, “Status”:“Off” }}
  5. { “obj_class”:“Cables”, “obj_instance”:“Cables-3”, “relation_tree”:“Start.HInfo.Cables.Cables-3”,
    “Cables”:{ “HInfoID”:“ABCD1234”, “Index”:“2”, “Name”:“WLAN”, “Status”:“Installed” }}
  6. { “obj_class”:“NFan”, “obj_instance”:“NFan-1”, “relation_tree”:“Start.HInfo.NFan.NFan-1”,
    “NFan”:{ “HInfoID”: “ABCD1234”, “Index”: “0” }}
  7. { “obj_class”:“Disk”, “obj_instance”:“Disk-1”, “relation_tree”:“Start.HInfo.Disk.Disk-1”,
    “Disk”:{ “HInfoID”:“ABCD1234”, “Index”:0, “Name”:“DISK0”, “MKMdl”:“THB”, “BW_MB”:694 }}
  8. { “obj_class”:“Partition”, “obj_instance”:“Partition-1”, “relation_tree”:“Start.HInfo.Disk.Disk-1.Partition.Partition-1”, “Partition”:{ “HInfoID”:“ABCD1234”, “DGID”:“ABCD1234”, “Index”:0, “Name”:“Not Used”, “SM”:500 }}
  9. { “obj_class”:“Partition”, “obj_instance”:“Partition-2”, “relation_tree”:“Start.HInfo.Disk.Disk-1.Partition.Partition-2”,
    “Partition”:{ “HInfoID”:“ABCD1234”, “DGID”:“ABCD1234”, “Index”:1, “Name”:“C:”, “SM”:476438 }}
  10. { “obj_class”:“Disk”, “obj_instance”:“Disk-2”, “relation_tree”:“Start.HInfo.Disk.Disk-2”, “Disk”:{ “HInfoID”:“ABCD1234”, “Index”:1, “Name”:“DISK1”, “MKMdl”:“JFlsh”, “BW_MB”:0 }}
  11. { “obj_class”:“Partition”, “obj_instance”:“Partition-1”, “relation_tree”:“Start.HInfo.Disk.Disk-2.Partition.Partition-1”, “Partition”:{ “HInfoID”:“ABCD1234”, “DGID”:“ABCD1234”, “Index”:0, “Name”:“E:”, “SM”:7727 }}

Is there any generic way to split the nested json file into multiple json along with with its relation tree at very first line (without any hard coding of Node/Tag) using Scala? Instant help or suggestion is appreciated.

Do you want to parse the file yourself or are you searching for a library that will do that for you?
Either way, you might want to look into upickle