Is there a general way to convert ROS messages into JSON format?
I would like to convert arbitrary ROS messages into JSON format. Is there an official way of doing this?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
I would like to convert arbitrary ROS messages into JSON format. Is there an official way of doing this?
Rosbridge provides you a JSON API to ROS
I just tried the rospy_message_converter.
Works really well! :)
Rosbridge is probably the better answer, but just in case, here's a method that will at least work on messages whose content can be rendered as a string with the python str()
function.
import json
import yaml
def msg2json(msg):
''' Convert a ROS message to JSON format'''
y = yaml.load(str(msg))
return json.dumps(y,indent=4)
if __name__ == "__main__":
from geometry_msgs.msg import PoseStamped
P = PoseStamped()
print msg2json(P)
{
"header": {
"stamp": {
"secs": 0,
"nsecs": 0
},
"frame_id": "",
"seq": 0
},
"pose": {
"position": {
"y": 0.0,
"x": 0.0,
"z": 0.0
},
"orientation": {
"y": 0.0,
"x": 0.0,
"z": 0.0,
"w": 0.0
}
}
}
I don't know much about this topic, but you might be able to find something useful in the newly announced mongodb_log package, I believe MongoDB uses JSON, and I think in that package they do automated conversions from ROS messages to JSON.
Asked: 2014-10-30 21:30:04 -0600
Seen: 18,478 times
Last updated: Oct 18 '17
Is it possible to have memory mapped messages in ROS?
who is heading the development of ROS?
Publisher Subscriber Teleoperation -- High Latency?
How to correctly use git with ROS
publish arrays to a topic on the command line
How to create a global listener for any ROS topic and extract all data from any message?
How to deserialize a ros message without knowing its type or content
What's the best way to convert a ros message to a string or xml?