JSON.parse is your friend and answer :)
//examples:
JSON.parse('{}'); // {}
JSON.parse('true'); // true
JSON.parse('"foo"'); // "foo"
JSON.parse('[1, 5, "false"]'); // [1, 5, "false"]
JSON.parse('null'); // null
MDN JSON.Parse details
Answer from Dory Zidon on Stack OverflowIs JSON.stringify() necessary for payloads via Shared Array?
Why does my array have "extra values". How can I JSON.stringify this info?
How to pass JSON array as input to GitHub Actions workflow?
streaming a large json object to a file to avoid memory allocation error
Well, JSON.stringify and JSON.parse are synchronous methods that unfortunately you can't pipe to and from. Like u/nissen2 suggests, you'll find some modules out there that will provide you what you're looking for.
Ah, I think I got it. Is there a way to permanently increase the amount of memory that node has access to? Thx.
While this may solve your problem in the mean time, I wouldn't suggest simply allocating more memory (especially with a huge JSON object.)
More on reddit.comVideos
This is weird but I am using a library that adds additional properties to array objects.
We have a simple array of numbers that looks like this:
[1,2,3,4,5,6]
This library I'm using (developed in house unfortunately) gives us the array but also adds extra props to it. When I console.log the array, what I actually see is:
[1,2,3,4,5,6, low: 1, high: 6, median: 3]
Unfortunately, JSON.stringify causes this info to get lost:
'[1,2,3,4,5,6]'
To make things more difficult, I do not know the exact properties that are "attached" to the array (sometimes its mean, sometimes its something completely domain specific).
How can I deal with these weird data types at runtime such that this info can be sent over the wire? Is it even possible? I imagine it breaks JSON schema of some sort.