ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How can I send JSON data to and from ROS?

asked 2017-11-05 13:10:20 -0500

qureeb gravatar image

I am currently working on a task that involves constant intercommunication between a web browser (using roslibjs) and the ROS system through the rosbridge server. Is there a way to send JSON-formatted data from the browser to a ROS node? I realize there is no JSON among the ROS system's standard data types.

edit retag flag offensive close merge delete

Comments

1

I'm confused: if you are already using roslibjs and rosbridge_suite, you are sending (and receiving) JSON data to (and from) ROS.

Can you clarify what it is you actually want to do?

gvdhoorn gravatar image gvdhoorn  ( 2017-11-05 14:12:36 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2017-11-05 14:14:41 -0500

gvdhoorn gravatar image

(follow up to my comment)

If you want to send JSON encoded data as part of a message to a ROS node, then I don't believe there are any special provisions for that.

Most straightforward would probably be to define a new message that stores the JSON string in a field. Any receiving node will have to know it's JSON though.

edit flag offensive delete link more
3

answered 2017-11-21 14:32:15 -0500

qureeb gravatar image

Thanks, I found a way out. I was expecting JSON to be one of ROS's standard message types. Not the case. I simply wrote a JSON-format data, stringified it, and sent it as std_msgs type.

edit flag offensive delete link more

Comments

3

This will certainly work. However it's not recommended since you're completely avoiding the message datatype checks and all the introspection tools are unable to help you. As @gvdhoorn suggests the recommended way to do this would be to define a custom message to hold your data.

tfoote gravatar image tfoote  ( 2017-11-21 15:05:25 -0500 )edit

but what if you want that stringified data into json form in c++ side.

AhteshamAziz gravatar image AhteshamAziz  ( 2019-10-07 09:48:17 -0500 )edit

@AhteshamAziz Then you need the C++ equivalent of Javascript's JSON.parse() utility, which can construct JSON object from a JSON-formatted String.

qureeb gravatar image qureeb  ( 2019-11-26 12:28:13 -0500 )edit

Question Tools

Stats

Asked: 2017-11-05 13:10:20 -0500

Seen: 4,480 times

Last updated: Nov 21 '17