Jump to content

JSON-RPC

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Clausc (talk | contribs) at 14:51, 14 May 2008 (Added and extended working drafts and current proposal). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

JSON-RPC is a remote procedure call protocol encoded in JSON. It is a very simple protocol (and very similar to XML-RPC), defining only a handful of data types and commands. In contrast to XML-RPC or SOAP, it allows for bidirectional communication between the service and the client, treating each more like peers and allowing peers to call one another or send notifications to one another. It also allows multiple calls to be sent to a peer which may be answered out of order.

Besides using HTTP for transport, one may use TCP/IP sockets. Using sockets, one can create much more responsive web applications with JSON-RPC, compared to polling data from a service with JSON-RPC over HTTP.

As of version 2.0, XINS supports both JSON and JSON-RPC.

History

Version Description Dated
1.0 Original version 2005
1.1 WD Working draft the specification is not yet released. Adds named parameters, adds specific error codes, and adds introspection functions. 2006-08-07
1.1 Alt suggestion for a simple JSON-RPC 1.1 Alternative proposal to 1.1 WD, differing on supported transport method(s) (and others). 2007-05-06
2.0 Specification proposal 2008-03-07

Example

Note that the examples below are examples according to the "1.1 Working Draft", which is outdated. For details look into the JSON-RPC Google Group.

A JSON invocation is carried on an HTTP POST request where the content-type is application/json. The format of the contents of a request might be something like that shown below.

{ 
"version": "1.1", 
"method": "confirmFruitPurchase", 
"id": "194521489", 
"params": [ 
    [ "apple", "orange", "pear" ], 
    1.123 
]
}

The format of a response might be something like this.

{ 
"version": "1.1", 
"result": "done", 
"error": null, 
"id": "194521489"
}

See also