json serialization

38 views
Skip to first unread message

DV Henkel-Wallace

unread,
Apr 9, 2018, 11:49:19 PM4/9/18
to Autobahn

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"

Tobias Oberstein

unread,
Apr 13, 2018, 9:00:18 AM4/13/18
to autob...@googlegroups.com, DV Henkel-Wallace
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}'

DV Henkel-Wallace

unread,
Apr 13, 2018, 3:11:36 PM4/13/18
to autob...@googlegroups.com
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.
> --
> 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.

Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages