Re: split a huge json file in separate per object files

[email protected] (Justin Rittenhouse) Thu, 13 Apr 2017 09:40:02 -0400
Newsgroups perl.perl4lib
Message-ID <CABr009aOXMZcJ_8=haTVdv9qD2+ty+7=rVvNCztkVppc=CpRCA@mail.gmail.com>
--001a113cda7077feb1054d0c7799
Content-Type: text/plain; charset=UTF-8

I haven't actually used the module, but I'd at least take a look at
JSON::Path.
It's like XPath, but for JSON.  I *have* used JSONpath before, just not in
Perl.  If you're interested in JSONPath, check out
http://goessner.net/articles/JsonPath/.

On Fri, Mar 10, 2017 at 8:57 AM, Marios lyberak <[email protected]>
wrote:

> Hello community,
>
> i have a json file, with a structure like this:
>
> {
> "106" : {
>       "id54011" : [
>          {
>             "partno1" : "16690617"
>          },
>          {
>             "partno2" : "5899180"
>          }
>       ],
>       "parts" : [
>          "0899180",
>          "16920617"
>       ],
>       "id5632" : [
>          {
>             "partno1" : "090699180"
>          }
>       ]
>    },
>    "560" : {
>       "id9452" : [
>          {
>             "partno2" : "1569855"
>          }
>       ],
>       "parts" : [
>          "03653624",
>          "15899855"
>       ],
>       "id578" : [
>          {
>             "partno3" : "0366393624"
>          },
>          {
>             "partno4" : "0363213624"
>          }
>       ]
>    }
> }
> I need to split this json, into files, like this:
>
> each json file, will consist of one object. 000106.json, and 000560.json.
> (all names, must gave 6 digits, so zeros must be added)
>
> I have tried to use eval for this, but no luck up to now...
>
> expected output: json file 1, named 000106.json:
>
>  {
>     "106" : {
>           "id54011" : [
>              {
>                 "partno1" : "16690617"
>              },
>              {
>                 "partno2" : "5899180"
>              }
>           ],
>           "parts" : [
>              "0899180",
>              "16920617"
>           ],
>           "id5632" : [
>              {
>                 "partno1" : "090699180"
>              }
>           ]
>        }
> and json file 2, named 000560.json:
>
> {
>     "560" : {
>               "id9452" : [
>                  {
>                     "partno2" : "1569855"
>                  }
>               ],
>               "parts" : [
>                  "03653624",
>                  "15899855"
>               ],
>               "id578" : [
>                  {
>                     "partno3" : "0366393624"
>                  },
>                  {
>                     "partno4" : "0363213624"
>                  }
>               ]
>            }
> How would you handle this?
>



-- 
*Justin Rittenhouse*
*Senior Application Development Technician, **Information Technology*
*Hesburgh Libraries*

208 Hesburgh Library
*o:* 574-631-3065
*e: *[email protected]

<http://library.nd.edu/>

--001a113cda7077feb1054d0c7799
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: base64

PGRpdiBkaXI9Imx0ciI+SSBoYXZlbiYjMzk7dCBhY3R1YWxseSB1c2VkIHRoZSBtb2R1bGUsIGJ1
dCBJJiMzOTtkIGF0IGxlYXN0IHRha2UgYSBsb29rIGF0wqA8c3BhbiBzdHlsZT0iY29sb3I6cmdi
KDAsMCwwKTtmb250LXNpemU6bWVkaXVtIj5KU09OOjpQYXRoLsKgIEl0JiMzOTtzIGxpa2UgWFBh
dGgsIGJ1dCBmb3IgSlNPTi7CoCBJICpoYXZlKiB1c2VkIEpTT05wYXRoIGJlZm9yZSwganVzdCBu
b3QgaW4gUGVybC7CoCBJZiB5b3UmIzM5O3JlIGludGVyZXN0ZWQgaW4gSlNPTlBhdGgsIGNoZWNr
IG91dMKgPC9zcGFuPjxmb250IGNvbG9yPSIjMDAwMDAwIiBzaXplPSIzIj48YSBocmVmPSJodHRw
Oi8vZ29lc3NuZXIubmV0L2FydGljbGVzL0pzb25QYXRoLyI+aHR0cDovL2dvZXNzbmVyLm5ldC9h
cnRpY2xlcy9Kc29uUGF0aC88L2E+LjwvZm9udD48L2Rpdj48ZGl2IGNsYXNzPSJnbWFpbF9leHRy
YSI+PGJyPjxkaXYgY2xhc3M9ImdtYWlsX3F1b3RlIj5PbiBGcmksIE1hciAxMCwgMjAxNyBhdCA4
OjU3IEFNLCBNYXJpb3MgbHliZXJhayA8c3BhbiBkaXI9Imx0ciI+Jmx0OzxhIGhyZWY9Im1haWx0
bzptYXJpb3MubHliZXJha0BnbWFpbC5jb20iIHRhcmdldD0iX2JsYW5rIj5tYXJpb3MubHliZXJh
a0BnbWFpbC5jb208L2E+Jmd0Ozwvc3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