Startoz
Member
Hi,
I want to load a large JSON file (more than 40k lines when formatted) and decode it.
The system that I'm using at the moment works perfectly fine if all the data is contained in one line (loading the text into a string takes less than 1 second).
However, if the JSON is formatted, it takes more than 25 seconds to load all the data into the string, since the script has to iterate over 40k+ lines.
This is the code that I'm using:
Is there a more efficient way of loading a big text/json file into a string?
Thanks!
I want to load a large JSON file (more than 40k lines when formatted) and decode it.
The system that I'm using at the moment works perfectly fine if all the data is contained in one line (loading the text into a string takes less than 1 second).
However, if the JSON is formatted, it takes more than 25 seconds to load all the data into the string, since the script has to iterate over 40k+ lines.
This is the code that I'm using:
Code:
/// @function decodeJsonFile(_fileName)
/// @param _fileName
var _file = argument0;
if (file_exists(_file)) {
var _json = "";
var _filePointer = file_text_open_read(_file);
while (!file_text_eof(_filePointer)) {
_json += file_text_read_string(_filePointer);
file_text_readln(_filePointer);
}
file_text_close(_filePointer);
var _decodedJson = json_decode(_json);
return _decodedJson;
} else {
return -1;
}
Thanks!