develooper Front page | perl.perl4lib | Postings from April 2017

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

From:
Justin Rittenhouse
Date:
April 13, 2017 13:40
Subject:
Re: split a huge json file in separate per object files
Message ID:
CABr009aOXMZcJ_8=haTVdv9qD2+ty+7=rVvNCztkVppc=CpRCA@mail.gmail.com
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 <marios.lyberak@gmail.com>
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: *jrittenh@nd.edu

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About