Simple (?) JSON question

I have zero experience with JSON, and this problem is a very small part of a much bigger project. Rather than spend a week figuring it out, I’m hoping some kind soul will put me on the right track.
I have some working php code that makes a JSON request. I want to make this request natively in a XOJO app.
Here is the request I need to make

{ "key": "YOUR_API_KEY", "request": { "module": "mymodule", "method": "GET", "username": "jim", "password": "letmein" } }

here is my attempt at implementing it

[code] dim j as new JSONItem
j.value(“key”) = “supersecretkey”
j.value(“module”) = “mymodule”
j.value(“method”) =“GET”
j.value(“username”) =“jim”
j.value(“password”) = “letmein”

myHTTPSock.Port = 443
myHTTPSock.Secure = true

myHTTPSock.SetRequestContent(j.tostring, “application/json; charset=utf-8”)
myHTTPSock.SendRequest(“GET”, “https://www.theserver.com/apiv3/”)
[/code]

How do I properly construct the JSON query?

the way you are bulding the json item, all the items are at the same level,
but in the request you need to make there is an element ‘ke’ and other elemnt ‘request’, and 'request contains the other elements module, method, username, password.

I the the correct code the have such structure is:

  dim j1 as new JSONItem
  dim j2 as new JSONItem
  j1.value("key") = "supersecretkey"
  j2.value("module") =  "mymodule"
  j2.value("method") ="GET"
  j2.value("username") ="jim"
  j2.value("password") = "letmein"
  j1.Child("request") = j2

Think of it as a Dictionary embedded within a Dictionary.

Thank you for the sample code and explanation as to how JSON is formed (like a dictionary). It makes sense now.

And remember, if you are using the new framework you can actually just use a dictionary.

[code]
Dim request As New Xojo.Core.Dictionary
request.Value(“module”) = “mymodule”
request.Value(“method”) =“GET”
request.Value(“username”) =“jim”
request.Value(“password”) = “letmein”

Dim json As New Xojo.Core.Dictionary
json.Value(“key”) = “supersecretkey”
json.Value(“request”) = request

Dim jsonText As Text = Xojo.Data.GenerateJSON(json)[/code]