Withdata Software

Split an array of nested JSON objects

I see a post https://stackoverflow.com/questions/67607384/split-an-array-of-nested-json-objects-using-jq, the poster gave an example JSON file:

{
  "storeId": "1412",
  "templateCheck": [
    {
      "rom": 37,
      "updateDate": "2021-05-09 07:53:17",
      "lhb": "2021-05-09 06:32:41",
      "templateCode": "REGULAR",
      "lId": "50-19-78-5C",
      "sk": "830066",
      "skUpdateDate": "2020-07-21 05:37:07",
      "battery": 30,
      "status": 1
    },
    {
      "rom": 37,
      "updateDate": "2021-05-09 07:54:02",
      "lhb": "2021-05-09 06:32:41",
      "templateCode": "REGULAR",
      "lId": "50-1B-FE-6E",
      "sk": "740541",
      "skUpdateDate": "2021-03-22 05:59:00",
      "battery": 30,
      "status": 1
    },
    {
      "rom": 37,
      "updateDate": "2021-05-09 07:52:05",
      "lhb": "2021-05-09 06:32:41",
      "templateCode": "REGULAR",
      "lId": "50-1C-22-6E",
      "sk": "846760",
      "skUpdateDate": "2021-05-08 03:34:22",
      "battery": 29,
      "status": 1
    }
  ]
}

He want to split it to JSON files like this:

{
    "storeId": "1412",
    "templateCheck": {
      "rom": 37,
      "updateDate": "2021-05-09 07:53:17",
      "lhb": "2021-05-09 06:32:41",
      "templateCode": "REGULAR",
      "lId": "50-19-78-5C",
      "sk": "830066",
      "skUpdateDate": "2020-07-21 05:37:07",
      "battery": 30,
      "status": 1
    {
}

He uses jq, I am not familiar with jq, I have a tool Data File Splitter, so I use this tool to split the JSON array.


Adjust “To Sublevel” and “Record On”.


In this case, we need to set “JSON Format” to “One by One”.

And the “Next” and “Next”, split, get smaller JSON files, like this:

{
	"storeId":"1412",
	"templateCheck":{
		"rom":"37",
		"updateDate":"2021-05-09 07:53:17",
		"lhb":"2021-05-09 06:32:41",
		"templateCode":"REGULAR",
		"lId":"50-19-78-5C",
		"sk":"830066",
		"skUpdateDate":"2020-07-21 05:37:07",
		"battery":"30",
		"status":"1"
	}
}