androidjsonanalyticssegment-io

SegmentIO analytics - Adding JSONObject inside properties


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"}

Solution

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

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