-3

I have a JSON file which contains around 20000 objects.

I would like to split the file into parts each containing a smaller number of object but without using any external libraries.

My current json

  [{"alt_party_id_type":"xyz","first_name":"child1ss","status":"1","dob":"2014-10-02 
     00:00:00.0","last_name":"childSs"},
    {"alt_party_id_type":"xyz","first_name":"suga","status":"1","dob":"2014-11-05 
      00:00:00.0","last_name":"test"},
           {"alt_party_id_type":"xyz","first_name":"test4a","status":"1","dob":"2000-11-05 
       00:00:00.0","last_name":"test4s"},
             {"alt_party_id_type":"xyz","first_name":"demo56","status":"0","dob":"2000-11-04 
    00:00:00.0","last_name":"Demo5"}, 
  {"alt_party_id_type":"xyz","first_name":"testsss","status":"1","dob":"1900-01-01 
     00:00:00.0","last_name":"testssssssssss"}, 
    {"alt_party_id_type":"xyz","first_name":"Demo1234","status":"0","dob":"2014-11-21 
  00:00:00.0","last_name":"Demo1"}, 
   {"alt_party_id_type":"xyz","first_name":"demo2433","status":"1","dob":"2014-11-13 
   00:00:00.0","last_name":"demo222"}, 
 {"alt_party_id_type":"xyz","first_name":"demo333","status":"0","dob":"2014-11-12 
00:00:00.0","last_name":"demo344"}, 
{"alt_party_id_type":"xyz","first_name":"Student","status":"1","dob":"2001-12-03 
 00:00:00.0","last_name":"StudentTest"}]

if split I need it to look like below
    
    
      - [
                {
                    "alt_party_id_type": "xyz",
                    "first_name": "demo56",
                    "status": "0",
                    "dob":"2000-11-04 
         00: 00: 00.0","last_name":"Demo5"}, 
         {
                        "alt_party_id_type": "xyz",
                        "first_name": "testsss",
                        "status": "1",
                        "dob":"1900-01-01 
             00: 00: 00.0","last_name":"testssssssssss"}, 
            {
                            "alt_party_id_type": "xyz",
                            "first_name": "Demo1234",
                            "status": "0",
                            "dob":"2014-11-21 
            00: 00: 00.0","last_name":"Demo1"}] 
dave110022
  • 64
  • 5

2 Answers2

1

Since your objects are simple (no sub objects or arrays) you can take your json string and just search for the next "{" then the next "}" and extract the json for that object. Do it in a loop, incrementing your position in a string. Package as many as you like with "[" and "]" and you have split your array. Process each package within the loop.

dave110022
  • 64
  • 5
0

What I'd do is write a program, which does the following ...

  1. Parse the big JSON file without loading it into memory like this
  2. Then you read out the data from it in increments of 100-200 and send to the API

You can also do the file split manually by using this approach and then import via Postman

Arthur Klezovich
  • 2,595
  • 1
  • 13
  • 17