{"id":22521,"date":"2024-11-01T06:54:14","date_gmt":"2024-11-01T06:54:14","guid":{"rendered":"http:\/\/www.withdata.com\/blog\/?p=22521"},"modified":"2024-11-01T06:54:14","modified_gmt":"2024-11-01T06:54:14","slug":"split-an-array-of-nested-json-objects","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/datafilesplitter\/split-an-array-of-nested-json-objects.html","title":{"rendered":"Split an array of nested JSON objects"},"content":{"rendered":"<p>I see a post <a href=\"http:\/\/Split an array of nested JSON objects using jq\" target=\"_blank\" rel=\"noopener\">https:\/\/stackoverflow.com\/questions\/67607384\/split-an-array-of-nested-json-objects-using-jq<\/a>, the poster gave an example JSON file:<\/p>\n<pre>{\r\n  \"storeId\": \"1412\",\r\n  \"templateCheck\": [\r\n    {\r\n      \"rom\": 37,\r\n      \"updateDate\": \"2021-05-09 07:53:17\",\r\n      \"lhb\": \"2021-05-09 06:32:41\",\r\n      \"templateCode\": \"REGULAR\",\r\n      \"lId\": \"50-19-78-5C\",\r\n      \"sk\": \"830066\",\r\n      \"skUpdateDate\": \"2020-07-21 05:37:07\",\r\n      \"battery\": 30,\r\n      \"status\": 1\r\n    },\r\n    {\r\n      \"rom\": 37,\r\n      \"updateDate\": \"2021-05-09 07:54:02\",\r\n      \"lhb\": \"2021-05-09 06:32:41\",\r\n      \"templateCode\": \"REGULAR\",\r\n      \"lId\": \"50-1B-FE-6E\",\r\n      \"sk\": \"740541\",\r\n      \"skUpdateDate\": \"2021-03-22 05:59:00\",\r\n      \"battery\": 30,\r\n      \"status\": 1\r\n    },\r\n    {\r\n      \"rom\": 37,\r\n      \"updateDate\": \"2021-05-09 07:52:05\",\r\n      \"lhb\": \"2021-05-09 06:32:41\",\r\n      \"templateCode\": \"REGULAR\",\r\n      \"lId\": \"50-1C-22-6E\",\r\n      \"sk\": \"846760\",\r\n      \"skUpdateDate\": \"2021-05-08 03:34:22\",\r\n      \"battery\": 29,\r\n      \"status\": 1\r\n    }\r\n  ]\r\n}\r\n<\/pre>\n<p>He want to split it to JSON files like this:<\/p>\n<pre>{\r\n    \"storeId\": \"1412\",\r\n    \"templateCheck\": {\r\n      \"rom\": 37,\r\n      \"updateDate\": \"2021-05-09 07:53:17\",\r\n      \"lhb\": \"2021-05-09 06:32:41\",\r\n      \"templateCode\": \"REGULAR\",\r\n      \"lId\": \"50-19-78-5C\",\r\n      \"sk\": \"830066\",\r\n      \"skUpdateDate\": \"2020-07-21 05:37:07\",\r\n      \"battery\": 30,\r\n      \"status\": 1\r\n    {\r\n}\r\n<\/pre>\n<p>He uses jq, I am not familiar with jq, I have a tool <a href=\"https:\/\/www.withdata.com\/data-file-splitter\/\" target=\"_blank\" rel=\"noopener\">Data File Splitter<\/a>, so I use this tool to split the JSON array.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/datafilesplitter\/split-nested-json-array.png\" alt=\"split nested json array\" width=\"722\" height=\"572\" style=\"max-width:100%;height:auto;display:block;\" \/><br \/>\nAdjust &#8220;To Sublevel&#8221; and &#8220;Record On&#8221;.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/datafilesplitter\/split-nested-json-array-format.png\" alt=\"set JSON format\" width=\"722\" height=\"572\" style=\"max-width:100%;height:auto;display:block;\" \/><br \/>\nIn this case, we need to set &#8220;JSON Format&#8221; to &#8220;One by One&#8221;.<\/p>\n<p>And the &#8220;Next&#8221; and &#8220;Next&#8221;, split, get smaller JSON files, like this:<\/p>\n<pre>{\r\n\t\"storeId\":\"1412\",\r\n\t\"templateCheck\":{\r\n\t\t\"rom\":\"37\",\r\n\t\t\"updateDate\":\"2021-05-09 07:53:17\",\r\n\t\t\"lhb\":\"2021-05-09 06:32:41\",\r\n\t\t\"templateCode\":\"REGULAR\",\r\n\t\t\"lId\":\"50-19-78-5C\",\r\n\t\t\"sk\":\"830066\",\r\n\t\t\"skUpdateDate\":\"2020-07-21 05:37:07\",\r\n\t\t\"battery\":\"30\",\r\n\t\t\"status\":\"1\"\r\n\t}\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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: { &#8220;storeId&#8221;: &#8220;1412&#8221;, &#8220;templateCheck&#8221;: [ { &#8220;rom&#8221;: 37, &#8220;updateDate&#8221;: &#8220;2021-05-09 07:53:17&#8221;, &#8220;lhb&#8221;: &#8220;2021-05-09 06:32:41&#8221;, &#8220;templateCode&#8221;: &#8220;REGULAR&#8221;, &#8220;lId&#8221;: &#8220;50-19-78-5C&#8221;, &#8220;sk&#8221;: &#8220;830066&#8221;, &#8220;skUpdateDate&#8221;: &#8220;2020-07-21 05:37:07&#8221;, &#8220;battery&#8221;: 30, &#8220;status&#8221;: 1 }, { &#8220;rom&#8221;: 37, &#8220;updateDate&#8221;: &#8220;2021-05-09 07:54:02&#8221;, &#8220;lhb&#8221;: &#8220;2021-05-09 06:32:41&#8221;, &#8220;templateCode&#8221;: &#8220;REGULAR&#8221;, &#8220;lId&#8221;: &#8220;50-1B-FE-6E&#8221;, &#8220;sk&#8221;: &#8220;740541&#8221;, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3144],"tags":[1418,2677,3405],"class_list":["post-22521","post","type-post","status-publish","format-standard","hentry","category-datafilesplitter","tag-json","tag-split-json","tag-split-json-array"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/22521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=22521"}],"version-history":[{"count":1,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/22521\/revisions"}],"predecessor-version":[{"id":22522,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/22521\/revisions\/22522"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=22521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=22521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=22521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}