Three tiered JSON with varying set of repeat blocks

Hi,

I am trying to generate a JSON for a product (example: Laptop) and its parts. In cases of Laptop, few parts are optional (example: Bluetooth) and others are not. So depending upon a laptop specification, the JSON structure might vary. Each part comes from a specific supplier. A part may or may not have sub-part(s) and accordingly sub-supplier(s).

I want to be able to generate random JSON structures with Products, its Parts and Sub-parts (if any). I am guessing that I need to maintain 3 datasets: Product, Parts and Sub-parts. Sub-parts dataset will have only entries if a part has sub-parts, and I expect JSON to show the sub-part array only if the part has sub-parts. What is the best way to set this up?

In general, what I am looking forward to is to be able to generate a JSON with Level1 record(Parent, maintained in dataset1) with related Level2 records (Children, maintained in dataset2) along with any related Level3 records (grand Children, maintained in dataset3). Child & Grandchild JSON array should be present only If there are related children or grandchildren are present. Also, It would be nice if I have option to specify 'display only first x children and grand children.

A representative JSON may look like this.

{
  "name": "Laptop Model-X",
  "itemSLNo": "222-2222-2222",
  "optionalDescription": "",
  "parts": [
    {
      "name": "Battery",
	  "itemSLNo": "333-333-33",
	  "optionalDescription": "42 Wh Battery",
	  "parts": []
    },
	{
      "name": "Software",
	  "itemSLNo": "",
	  "optionalDescription": "",
	  "parts": [
		{
		  "name": "Linux v x.x",
		  "itemSLNo": "333-344-33",
		  "optionalDescription": "",
		  "parts": []
		},
		{
		  "name": "Photosoft-Pro 15",
		  "itemSLNo": "322-333-33",
		  "optionalDescription": "",
		  "parts": []
		}
		]
    },
    {
      "name": "Processor",
	  "itemSLNo": "7777-333-33",
	  "optionalDescription": "",
	  "parts": []
    },
    {
      "name": "Screen",
	  "itemSLNo": "333-654-33",
	  "optionalDescription": "",
	  "parts": []
    },
    {
      "name": "Optional Parts",
	  "itemSLNo": "",
	  "optionalDescription": "",
	  "parts": [
		{
		  "name": "Camera",
		  "itemSLNo": "777-333-222",
		  "optionalDescription": "5 m-px front camera",
		  "parts": []
		},
		{
		  "name": "Bluetooth",
		  "itemSLNo": "876-998-0098",
		  "optionalDescription": "BT 4.1",
		  "parts": []
		},
		{
		  "name": "Graphics co-processor",
		  "itemSLNo": "776-445-0987",
		  "optionalDescription": "",
		  "parts": []
		}	
	  ]
    }
  ]
}