Arrays as values in named parameters

1,139 views
Skip to first unread message

Stephan Arts

unread,
Aug 21, 2010, 6:25:22 AM8/21/10
to JSON-RPC
Hi,

I am working on a stream based C library implementing this spec, and I
came across one implementation-question that I couldn't answer by
reading the spec.

Does the params field allow for array values of named parameters?

Like:
{"jsonrpc" : "2.0", "method" : "example", "params" : { "array" : [ 0 ,
1 , 2 , 3 ] , "number", 3 }, "id", 1 }

Personally, I don't think there is any need for such complex
structures in an RPC spec. But before I decide not to implement it,
I'd like to verify that it should not work like this.

Regards,
Stephan

Matt (MPCM)

unread,
Aug 21, 2010, 7:44:41 AM8/21/10
to JSON-RPC
Yes to your question. The values of parameters, named or otherwise can
be anything that is valid json. Of course the server gets to decide
what it is going to accept and handle.

But, what you posted was not valid json (or json-rpc). If you meant
something like the below:

{
"jsonrpc" : "2.0",
"id": 1,
"method" : "example",
"params" : {
"array" : [0,1,2,3],
"number": 3
}
}

Then that is a valid request object, calling "example" and passing two
named parameters, one called "array" which also has an array value,
and one called number which is passing the value of 3.

Hope that helps clarify.

--
Matt (MPCM)

Stephan Arts

unread,
Aug 21, 2010, 8:52:07 AM8/21/10
to JSON-RPC
Thank you, that indeed answers my question.

It does raise the bar a bit when it comes to (de)serializing the
data. :-)

Lorenzo Pastrana

unread,
Aug 23, 2010, 4:19:33 AM8/23/10
to json...@googlegroups.com

If you're affraid of deserializing ... you're not talking JSON ...
What you need is a plain JSON parser, then everything becomes easyer .. ;P

This one is pretty lightweight :
http://fara.cs.uni-potsdam.de/~jsg/json_parser

See http://www.json.org for alternatives.

Lo.


Vladimir Dzhuvinov

unread,
Sep 12, 2010, 4:51:33 PM9/12/10
to JSON-RPC
> Personally, I don't think there is any need for such complex
> structures in an RPC spec.

Initially I thought the same, but later practice showed that
occasionally array or object parameter values become necessary :)

For example, I've got an RPC method for an LDAP record get operation
and it has an optional array parameter that specifies the attributes
to retrieve.

Here is the method's API to get an idea:

http://software.dzhuvinov.com/json2ldap-api.html#ldap.getEntry


Vladimir

--
Vladimir Dzhuvinov :: software.dzhuvinov.com
Reply all
Reply to author
Forward
0 new messages