I use PHP on a shared server to access an external site through an API that returns JSON containing 2 levels of data (Level 1: Performer and Level 2: Category array inside the executor). I want to convert this to a multidimensional associative array WITHOUT USING json_decode (it uses too much memory for this use !!!)
Sample JSON data:
[ { "performerId": 99999, "name": " Any performer name", "category": { "categoryId": 99, "name": "Some category name", "eventType": "Category Event" }, "eventType": "Performer Event", "url": "http://www.novalidsite.com/something/performerspage.html", "priority": 0 }, { "performerId": 88888, "name": " Second performer name", "category": { "categoryId": 88, "name": "Second Category name", "eventType": "Category Event 2" }, "eventType": "Performer Event 2", "url": "http://www.novalidsite.com/somethingelse/performerspage2.html", "priority": 7 } ]
I tried using substr and split the "[" and "]".
Then made a call:
preg_match_all('/\{([^}]+)\}/', $input, $matches);
This gives me a row for each row, but truncates after the final "}" category data.
How can I return FULL ROW of AS ARRAY data using something like preg_split, preg_match_all, etc. INSTEAD of heavy calls like json_decode to a common JSON string?
As soon as I have an array with each correctly identified line, I MAY than execute json_decode on this line without overloading the memory on the shared server.
For those who want to get more details about using json_decode, causing an error:
$aryPerformersfile[ ] = file_get_contents('https://subdomain.domain.com/dir/getresults?id=1234'); $aryPerformers = $aryPerformersfile[0]; unset($aryPerformersfile); $mytmpvar = json_decode($aryPerformers); print_r($mytmpvar); exit;