im trying to decode large json file 222mb file.
i understand i can not use json_decode directly by using file_get_contents() to read whole file and decode whole string, as it would consume alot of memory and would return nothing(this is what its doing so far.)
so i went to try out libraries, The one i tried recently is JSONParser. what it does reads the objects one by one in json array.
but due to lack of documentation there, i want to ask here if anyone has worked with this library.
this is the example test code from github
// initialise the parser object
$parser = new JSONParser();
// sets the callbacks
$parser->setArrayHandlers('arrayStart', 'arrayEnd');
$parser->setObjectHandlers('objStart', 'objEnd');
$parser->setPropertyHandler('property');
$parser->setScalarHandler('scalar');
/*
echo "Parsing top level object document...\n";
// parse the document
$parser->parseDocument(__DIR__ . '/data.json');*/
$parser->initialise();
//echo "Parsing top level array document...\n";
// parse the top level array
$parser->parseDocument(__DIR__ . '/array.json');
how to use a loop and save the object in php variable that we can easily decode to php array for our further use.
this would take some time as it would be doing this one by one for all objects of json array, but question stands how to loop over it using this library, or isn't there such option.
Or are any other better options or libraries for this sorta job?