json object in request message

Former Member
Former Member
I'm working on a widget that needs to make a json request. That request parameter is a json object.
It's something like:
www.url.com/bla "A", "b": {"c": "C"}}

Is there a simple clean way to create this?

My current solution is:

var parameters = {"request" => "{\"a\": \"A\", \"b\": {\"c\": \"C\"}}"};
Comm.makeJsonRequest("http://www.url.com/bla", parameters, {}, method(:callback));


I could make a helper class to translate a library to a json object, but if something like that already exist in the CIQ framework, I'd prefer to use that.
  • Former Member
    Former Member over 9 years ago
    I'll assume nothing like this exists, so I wrote my own helper function.
    Thought I'd share it for anyone else who needs such a thing:

    function toJson(dictionary) {
    if (dictionary == null || dictionary.size() == 0) {
    return "{}";
    }

    var keys = dictionary.keys();
    var json = "";
    var value;

    for (var i = 0; i < keys.size(); ++i) {
    json += ",\"" + keys+ "\":";
    value = dictionary.get(keys);
    if (value instanceof Lang.Dictionary) {
    json += toJson(value);
    }
    else if (value instanceof Lang.String) {
    json += "\"" + value + "\"";
    }
    else {
    json += value;
    }
    }

    return "{" + json.substring(1, json.length()) + "}";
    }
    [/CODE]