json serialization

#1

We have four clients, one each in python (data source), java, js, and C++ (latter three data consumers), all using Autobahn.

When we send JSON arguments, they get serialized by python using the single quote as the string delimiter (e.g. {‘id’: 123}). If we manually use json.dumps(argument_dict) the stuff is properly encoded JSON.

The python serialization with single quotes is happily accepted by the java and js clients but is rejected the C++ WAMP client.

If json.dumps is used then the java client gets a string rather than json (but C++ can parse it, with nlohmann/json or rapidjson).

What’s the intended behavior here? I’m honestly surprised that the Java version works at all with this python output. I’m the C++ dev and the others suggest I just string replace the single quotes with double quotes, which sounds like a fragile “fix” to me. I’d like to have us all doing “the right thing”

0 Likes

#2

Python produces correct JSON:

oberstet@thinkpad-t430s:~/scm/crossbario/autobahn-cpp$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

import json
json.dumps({'id': 123})

'{"id": 123}'

···

Am 10.04.2018 um 05:49 schrieb DV Henkel-Wallace:

We have four clients, one each in python (data source), java, js, and C++
(latter three data consumers), all using Autobahn.

When we send JSON arguments, they get serialized by python using the single
quote as the string delimiter (e.g. {'id': 123}). If we manually use
json.dumps(argument_dict) the stuff is properly encoded JSON.

The python serialization with single quotes is happily accepted by the java
and js clients but is rejected the C++ WAMP client.

If json.dumps is used then the java client gets a string rather than json
(but C++ can parse it, with nlohmann/json or rapidjson).

What's the intended behavior here? I'm honestly surprised that the Java
version works at all with this python output. I'm the C++ dev and the
others suggest I just string replace the single quotes with double quotes,
which sounds like a fragile "fix" to me. I'd like to have us all doing
"the right thing"

0 Likes

#3

Thanks Tobias! It seems if you neglect to do json.dumps() with your arguments the javascript and java autobahn clients will "just work" with what python produces. But following the examples that ship with the python version is the right thing to do, and our team thankfully decided to do the right thing.

···

On Apr 13, 2018, at 06:00, Tobias Oberstein <tobias.o...@gmail.com> wrote:

Python produces correct JSON:

oberstet@thinkpad-t430s:~/scm/crossbario/autobahn-cpp$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

import json
json.dumps({'id': 123})

'{"id": 123}'

Am 10.04.2018 um 05:49 schrieb DV Henkel-Wallace:

We have four clients, one each in python (data source), java, js, and C++
(latter three data consumers), all using Autobahn.

When we send JSON arguments, they get serialized by python using the single
quote as the string delimiter (e.g. {'id': 123}). If we manually use
json.dumps(argument_dict) the stuff is properly encoded JSON.

The python serialization with single quotes is happily accepted by the java
and js clients but is rejected the C++ WAMP client.

If json.dumps is used then the java client gets a string rather than json
(but C++ can parse it, with nlohmann/json or rapidjson).

What's the intended behavior here? I'm honestly surprised that the Java
version works at all with this python output. I'm the C++ dev and the
others suggest I just string replace the single quotes with double quotes,
which sounds like a fragile "fix" to me. I'd like to have us all doing
"the right thing"

--
You received this message because you are subscribed to the Google Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autobahnws+...@googlegroups.com.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/20e8f35c-6d54-e599-8a31-9ac6841bd3fb%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

0 Likes