I am trying to JSONify a Javascript object only to get an "Invalid string length" error. I decided to break the object into smaller parts, use JSON.stringify in small parts, and add each segment to the file.
I first converted the javascript object to an array and split it into smaller parts.
{'key1': [x, y, z], 'key2' : [p, q, l], ...... } - a sample of the original object in JSON notation. Each character x, y, z, p, q, l is an abbreviation for the base line 64, which is long enough to cause the problem of overflowing the length of the string.
[ ['key1', x], ['key1', y], ['key1', z], ['key2', p], ....... ] - converted array
var arrays = [] while (arrayConvertedObject.length > 0) arrays.push(arrayConvertedObject.slice(0, 2)) }
Then I was going to create a javascript object for each of the smaller arrays in arrays to use JSON.stringify individually.
[["key1", x], ["key1", y]] - array 1 [["key1", z], ["key2", p]] - array 2
When I convert each smaller array to a Javascript object and use JSON.stringify, I get:
{"key1": [x, y]} - string 1 {"key1": [z], "key2": [p]} - string 2
The problem is that string concatenation with additional manipulation },{ will not save the original data:
{"key1": [x, y], "key1": [z], "key2": [p]}
When I want obj["key1"] have [x, y, z] , the JSON above will parse obj["key1"] = [z] .
If I do not use JSON.stringify on smaller objects, it will defeat my original JSONifying target of a large javascript object. But if I do this, I cannot combine JSONified small objects with duplicate keys.
Is there a better way to handle the JSON.stringify "Invalid String Length" error? If not, is there a way to combine JSONified objects without overriding duplicate keys?
Thanks for reading the long question. Any help would be appreciated.