Go to the documentation of this file.00001 import json
00002 from rospy_message_converter import message_converter
00003
00004 def convert_json_to_ros_message(message_type, json_message):
00005 """
00006 Takes in the message type and a JSON-formatted string and returns a ROS
00007 message.
00008
00009 Example:
00010 message_type = "std_msgs/String"
00011 json_message = '{"data": "Hello, Robot"}'
00012 ros_message = convert_json_to_ros_message(message_type, json_message)
00013 """
00014 dictionary = json.loads(json_message)
00015 return message_converter.convert_dictionary_to_ros_message(message_type, dictionary)
00016
00017 def convert_ros_message_to_json(message):
00018 """
00019 Takes in a ROS message and returns a JSON-formatted string.
00020
00021 Example:
00022 ros_message = std_msgs.msg.String(data="Hello, Robot")
00023 json_message = convert_ros_message_to_json(ros_message)
00024 """
00025 dictionary = message_converter.convert_ros_message_to_dictionary(message)
00026 json_message = json.dumps(dictionary)
00027 return json_message