I am trying to make a dictionary of Point, in which the key is an id (unique integer number) and value is the point itself. Please see the sample code below:
from geometry_msgs.msg import Point
indices = [1, 2, 3, 4]
p1 = Point(11, 12, 13)
p2 = Point(21, 22, 23)
p3 = Point(31, 32, 33)
p4 = Point(41, 42, 43)
points = [p1, p2, p3, p4]
points_info = {indices[i]:p for i, p in enumerate(points)}
I want to convert it to JSON. So I am using JSON library as below:
import json
print json.dumps(points_info)
However, it throws following error:
TypeError: x: 11
y: 12
z: 13 is not JSON serializable
Any workaround, please? Note that I am using Python 2.7 in ROS Indigo on Ubuntu 14.04 LTS PC.