Skip to content
BENIBIX Learn

JSON-RPC

Development🔌 APIsAPI Architecture Styles

Also known as JSON-RPC 2.0, JSON Remote Procedure Call

A way for one program to ask another to do a job. The note is in JSON.

Think of it like

Think of it like a note that says which job to do and what to use. The answer note has the same number.

Example

Lucy's app sends a JSON-RPC request asking for the sum of 3 and 4, with id 1. The reply says the result is 7 and carries id 1, so she knows which request it answers.

Why it matters

It is small and easy to read. MCP and many other tools are built on it.

Definition

JSON-RPC is a simple way for one program to ask another to run a function, using JSON messages. A request names the method, gives its inputs and carries an id. The reply carries the same id, with either a result or an error. A message with no id is a notice that needs no reply. It does not care how the messages travel, so it works over HTTP, sockets or plain input and output. The current version, 2.0, dates from 2010.

Example code

json
{ "jsonrpc": "2.0", "method": "add", "params": [3, 4], "id": 1 }

{ "jsonrpc": "2.0", "result": 7, "id": 1 }
A request and its reply. The shared id ties the answer to the question.
The request names a method and carries an id. The reply brings back the same id with the result.

Common mistake

Reusing the same id for two requests at once. The replies can then be matched to the wrong question.

Key takeaways

  1. 1
    Method, inputs, id. Every request.
  2. 2
    Same id back. Matches the reply.
  3. 3
    Any channel. HTTP, sockets or pipes.