Ask Your Question

Is there a general way to convert ROS messages into JSON format?

asked 2014-10-30 21:30:04 -0500

liangfok gravatar image

updated 2014-10-30 21:30:27 -0500

I would like to convert arbitrary ROS messages into JSON format. Is there an official way of doing this?

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

answered 2014-10-31 12:30:53 -0500

Wolf gravatar image

updated 2015-11-03 09:06:32 -0500

lucasw gravatar image

Rosbridge provides you a JSON API to ROS

edit flag offensive delete link more


Is there a way to just run rosbridge_library (to just get ROS messages to JSON conversion)?

parzival gravatar image parzival  ( 2020-06-24 11:07:56 -0500 )edit

answered 2015-11-02 06:25:20 -0500

updated 2015-11-02 06:25:54 -0500

I just tried the rospy_message_converter.

Works really well! :)

edit flag offensive delete link more

answered 2017-10-18 16:17:29 -0500

vschmidt gravatar image

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
edit flag offensive delete link more

answered 2014-10-31 12:15:06 -0500

Airuno2L gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2014-10-30 21:30:04 -0500

Seen: 10,597 times

Last updated: Oct 18 '17