So currently, I am getting data via TCP connection and we can tell if a string is a valid JSON object using something like:
let body = '';
client.on('data', (chunk) => {
body += chunk.toString();
try {
let data = JSON.parse(body);
// data is valid json
}
catch (e) {}
});
While this works, can we get all valid Objects in a chunk? Let's say we have
const chunk = // an incomplete object like { "list": [ { "id": 1 }, { "id":
So in the sample, how can we get a valid object in a string? I'm trying to get { "id": 1 } because it's the only valid object in the string.
{and}s, but pretty sure this isn't the sort of thing you should need to do in the first place