How to send a more complex JSON body using makeWebRequest

Former Member
Former Member
Hello @all,

I do know how to send a simple (flat) JSON using makeWebRequest.

But I could not figure out how a bit more complex JSON like the following could be sent:

{"topic":"topic/watch","type":"watch","name":"button1","priority":1,"payload":[["ClickType","SerialNumber","Time"],["button1","455664445671",0]]}

Does anybody know how this JSON could look like as dictionary?
Or is it impossible to send such an object structure using makeWebRequest?

Thx in advance
  • It looks pretty much like the JSON (replace the : separator with => and you're done).

    var params = {
    "topic" => "topic/watch",
    "type" => "watch",
    "name" => "button1",
    "priority" => 1,
    "payload" => [
    [ "ClickType", "SerialNumber", "Time" ],
    [ "button1", "455664445671", 0 ]
    ]
    };


    If you are trying to build such a dictionary...

    var params = {};

    params.put("topic", "topic/watch");
    params.put("type", "watch");
    params.put("name", "button1");
    params.put("priority", 1);

    var payload = [];
    payload.add([ "ClickType", "SerialNumber", "Time" ]);
    payload.add([ "button1", "455664445671", 0 ]);

    params.put("payload", payload);
  • Former Member
    Former Member
    Thx!

    Thank you very much Travis!
    ...exactly what I was looking for!
  • I have found that if I'm connected to an iPhone, it's necessary to surround number values with quotes or the transfer fails.
  • Former Member
    Former Member
    ...still questions

    I'm still humbled...

    what I do have is a JSON as string (like posted yesterday). This string comes from an app setting value. So it is a string, not a dictionary.

    The only thing I need do is, I want to post (or PUT) the exact string using makeWebRequest to a server.

    Is it correct that I need to parse the whole JSON on my own to a dictionary to become able to post it using makeWebRequest?

    So I do need to write a JSON parser on my own?

    That sounds a bit strange for such a simple proposition.

    Is there a JSON parser I could use?
    Or is there a possibility to convert a string value to an object (using Travis' first approach)?
    (Or is there a way to send a string as HTTP PUT body?)
  • Since you're receiving a string from App Settings, you're probably going to need to write your own JSON parser.


    Just thinking out loud here, but another option would be to not use App Settings, but instead do the configuration via the Web. The Web UI could provide a really nice JSON builder interface, but the real benefit is that it can return JSON directly into your app, which you can then save, and then use on subsequent calls.