json_message_converter.py
Go to the documentation of this file.
1 import json
2 from rospy_message_converter import message_converter
3 
4 def convert_json_to_ros_message(message_type, json_message, strict_mode=True):
5  """
6  Takes in the message type and a JSON-formatted string and returns a ROS
7  message.
8 
9  If strict_mode is set, an exception will be thrown if the json message contains extra fields
10 
11  Example:
12  message_type = "std_msgs/String"
13  json_message = '{"data": "Hello, Robot"}'
14  ros_message = convert_json_to_ros_message(message_type, json_message)
15  """
16  dictionary = json.loads(json_message)
17  return message_converter.convert_dictionary_to_ros_message(message_type, dictionary, strict_mode=strict_mode)
18 
20  """
21  Takes in a ROS message and returns a JSON-formatted string.
22 
23  Example:
24  ros_message = std_msgs.msg.String(data="Hello, Robot")
25  json_message = convert_ros_message_to_json(ros_message)
26  """
27  dictionary = message_converter.convert_ros_message_to_dictionary(message)
28  json_message = json.dumps(dictionary)
29  return json_message
def convert_json_to_ros_message(message_type, json_message, strict_mode=True)


rospy_message_converter
Author(s): Brandon Alexander
autogenerated on Thu Mar 5 2020 03:12:49