Receiving "chunked" data (json arrays) on the front-end via "xhr" (onprogress).
Handling delayed chunks is easy - just remember response length and offset. The challenge comes when multiple "chunked" responses arrive simultaneously, resulting in an unparsable final response due to incorrect json format.
Structure:
[array 1][array 2] ... [array N]
Example:
[{"response": [{"itemId": 1}]}][{"response": [{"itemId": 2}]}]
Question: How can this be parsed? Attempts with regular expressions failed when dealing with sub-arrays within response bodies, like in the example given above.
Current matching pattern:
1) {"response": [{"itemId": 1}
2) {"response": [{"itemId": 2}
Desired output:
1) {"response": [{"itemId": 1}]}
2) {"response": [{"itemId": 2}]}
Looking for alternative approaches or tweaks to the current regular expression:
\[(.*?)\]/gi
Any suggestions on using regular expressions or recommendations for different methods? Appreciate any help!