You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
string smsg((char*)buff, len);
if (debuglevel_&1) cout << "Raw data Str: " << smsg << endl;
json jmsg = json::parse(smsg);
Alternative code:
stringstream ss;
ss<<smsg;
while (! ss.eof()) {
json jmsg;
ss >> jmsg;
Output:
parse error - unexpected '{'; expected end of input
Expected result:
I would like to be able to parse multiple concatenated JSON strings.
A possible implementation could be if the result were an array of json objects. like ‘[{…},{…},{…}]’
This could be achieved by replacing ‘}{‘ with ‘},{‘ and inserting a ‘[‘ and a ‘]’ at the beginning and ending of the string. (My current workaround.) But this is not a very robust implementation, would need to replace all possible ‘}\r\n{‘ … variant, not to mention strings containing “}{”. Also not very efficient, needs to pseudo pre parse the input. (It would help somewhat if json could accept whitespace* separated objects in arrays not requiring comma, though that would not be valid JSON. This could be a relaxed parsing, instead of strict.)
Second possible implementation (preferred IMHO) for the parsing to be resumable. Meaning extract one JSON object from a stream, leave the read position and start from there the next time. Or in case if it’s a string provide a method to query how much characters were processed, so that part can be “removed” from the input string and the rest can be parsed again. (Like: string smsg ((char*)&buff[position], len-position); … position+=jmsg.??)
I have found these related issues: #367 #210
The suggested workaround here (counting matching ‘{‘ ’}’ would not work if any string inside the JSON contained non matching ‘{‘,’}’ characters like "{"test3":"}"}").
Thank you for all your work and efforts.
The text was updated successfully, but these errors were encountered:
Yes, this should be fixed with #367. I shall close this ticket.
When I added support for streams, I never thought about the fact that streams could be reused. I hope to be able to add this feature without too much refactoring.
Hi, I just started using your library, so far I like your design, but I run into this problem.
Example input (received from TCP socket):
Code fragment:
Alternative code:
Output:
Expected result:
I would like to be able to parse multiple concatenated JSON strings.
A possible implementation could be if the result were an array of json objects. like ‘[{…},{…},{…}]’
This could be achieved by replacing ‘}{‘ with ‘},{‘ and inserting a ‘[‘ and a ‘]’ at the beginning and ending of the string. (My current workaround.) But this is not a very robust implementation, would need to replace all possible ‘}\r\n{‘ … variant, not to mention strings containing “}{”. Also not very efficient, needs to pseudo pre parse the input. (It would help somewhat if json could accept whitespace* separated objects in arrays not requiring comma, though that would not be valid JSON. This could be a relaxed parsing, instead of strict.)
Second possible implementation (preferred IMHO) for the parsing to be resumable. Meaning extract one JSON object from a stream, leave the read position and start from there the next time. Or in case if it’s a string provide a method to query how much characters were processed, so that part can be “removed” from the input string and the rest can be parsed again. (Like:
string smsg ((char*)&buff[position], len-position); … position+=jmsg.??
)I have found these related issues:
#367
#210
The suggested workaround here (counting matching ‘{‘ ’}’ would not work if any string inside the JSON contained non matching ‘{‘,’}’ characters like "{"test3":"}"}").
Thank you for all your work and efforts.
The text was updated successfully, but these errors were encountered: