zenoh icon indicating copy to clipboard operation
zenoh copied to clipboard

REST API Inconsistency processing JSON5

Open joshnewans opened this issue 5 months ago • 1 comments

When using the REST API, if data is sent with JSON5 encoding (in our application, just so we can parse NaN and Infinity) it attempts to deserialise it as a JSON object and falls back to base64 if it cannot.

This seems reasonable for the other two JSON types, but for JSON5 where we are regularly sending non-compliant JSON, the other end has no way of knowing (I think) whether it needs to do the decode itself or not.

I think JSON5 should instead be treated the same as TEXT_PLAIN (which is in the next block of code) where it knows it is text so does not need to base64 encode, but puts the onus on the reader to parse with a JSON5 parser.

Happy to submit a PR if this is acceptable, but I guess it will break anyone who is relying on the current behaviour and doesn't actually use any features of JSON5?

https://github.com/eclipse-zenoh/zenoh/blob/5d4420f8c5356f87bb5c05f8188bb7a863823959/plugins/zenoh-plugin-rest/src/lib.rs#L127-L136

joshnewans avatar Jul 30 '25 03:07 joshnewans

IMO it seems counter-productive to try de-serialize as JSON when we know the encoding to be JSON5. But as you mentioned, it may not be worth breaking compatibility for all existing code that depends on this behavior.

oteffahi avatar Jul 31 '25 12:07 oteffahi