I have a large (200 meg) JSON file (actually a text file) that is apparently too large to decode in PHP using json_decode. There is apparently no native way in PHP to decode large files and you apparently need to use a 3rd party library which my host frowns upon.
Accordingly, I had the idea of converting the JSON file into a MYSQL database table.
Here is the format of the JSON. Can anyone suggest code to import this into a MYSQL database?
Here is my code:
//This works fine
$longstr = file_get_contents("json-largefile.txt");
//this works with small sample file but fails with large 200 mb file
$array = json_decode($str, true);
Here is the format of the json/txt file after help from this question:
[{"index":"tolstoy","index_id":0,"type":"introduction","line_id":1,"book_name":"War and Peace", "speech_number":"","line_number":"","speaker":"","text_entry":"Introduction"},
{"index":"tolstoy","index_id":1,"type":"heading","line_id":2,"book_name":"War and Peace","speech_number":"","line_number":"","speaker":"","text_entry":"Tolstoy's World"}]
I have tried the approaches in this question that get quite involved without success. Is there a straightforward one shot way to do this that does not involve iterating line for line or converting to .csv?
Thanks for any suggestions.