SegmentIO analytics - Adding JSONObject inside properties

152 Views Asked by At

I am trying to add JSONObject inside properties of segmentIO analytics but it is showing json as String on server.

Here is my code:

JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("abc", "xyz");
properties.putValue("extras", jsonObject);
Analytics.with(context).track(event, properties);

Output:

extras : "{"abc","xyz"}"

Expected Output:

extras : {"abc","xyz"}
1

There are 1 best solutions below

0
On BEST ANSWER

Use JSONParser (org.json.simple.parser.JSONParser)

JSONParser parser = new JSONParser();
JSONObject object = (JSONObject) parser.parse(json);
properties.putValue("extras", object);