Table of contents
1.
Introduction
2.
Primary Features
3.
Using RedisJSON
3.1.
With Redis-CLI
3.2.
With Redis-Py
3.3.
Building on Ubuntu 20.04
4.
Loading the Module to Redis
5.
Frequently Asked Questions
5.1.
What is RedisJSON?
5.2.
Is RedisJSON open-source?
5.3.
Which data-type RedisJSON implements?
5.4.
What is the function of JSON.STRLEN and JSON.STRAPPEND?
6.
Conclusion
Last Updated: Aug 13, 2025

JSON and Redis Stack

Author Devansh
0 upvote

Introduction

In Redis Stack, JSON support is provided through the RedisJSON module. RedisJSON is a Redis module that supports JSON in Redis. RedisJSON allows you to store, update, and retrieve JSON values in Redis the same way you would any other Redis data type. RedisJSON also integrates with RediSearch to allow you to index and query your JSON documents.

RedisJSON is a Redis module that implements as a native data type ECMA-404, the JSON Data Interchange Standard. It allows you to save, update, and retrieve JSON data from Redis keys (documents).

Primary Features

1. The JSON standard is fully supported.

2. JSONPath syntax is used to select items within documents.

3. Documents are stored in a tree structure as binary data, allowing for quick access to sub-elements.

4. All JSON value types have typed atomic operations.

5. When paired with RediSearch, secondary index support is provided.

Using RedisJSON

It's best to start using the Redis CLI to understand how to utilize RedisJSON. You must be connected to a Redis server that supports RedisJSON for this to work.

With Redis-CLI

Begin by running Redis-CLI. JSON.SET, which associates a Redis key with a JSON value, is the first RedisJSON command to attempt. Any JSON value, such as a string, can be used.

127.0.0.1:6379> JSON.SET foo $ '"dev"'
OK
127.0.0.1:6379> JSON.GET foo $
"[\"dev\"]"
127.0.0.1:6379> JSON.TYPE foo $
1) string

 

JSON.GET and JSON.TYPE perform this regardless of the value's type, although JSON.GET's prettifying skills are particularly impressive. Take note of how the commands are preceded by a period, i.e. (in this case it just means the root). Here are a few more string operations:

127.0.0.1:6379> JSON.STRLEN foo $
1) (integer) 3
127.0.0.1:6379> JSON.STRAPPEND foo $ '"loper"'
1) (integer) 6
127.0.0.1:6379> JSON.GET foo $
"[\"loper\"]"

 

JSON.STRLEN returns the length of the string, while JSON.STRAPPEND appends another string to it. Numbers can be multiplied and incremented:

127.0.0.1:6379> JSON.SET num $ 0
OK
127.0.0.1:6379> JSON.NUMINCRBY num $ 1
"[1]"
127.0.0.1:6379> JSON.NUMINCRBY num $ 1.5
"[2.5]"
127.0.0.1:6379> JSON.NUMINCRBY num $ -0.75
"[1.75]"
127.0.0.1:6379> JSON.NUMMULTBY num $ 24
"[42]"

 

A better example would use an array or an object:

127.0.0.1:6379> JSON.SET anotherexample $ '[ true, { "answer": 42 }, null ]'
OK
127.0.0.1:6379> JSON.GET anotherexample $
"[[true,{\"answer\":42},null]]"
127.0.0.1:6379> JSON.GET anotherexample $[1].answer
"[42]"
127.0.0.1:6379> JSON.DEL anotherexample $[-1]
(integer) 1
127.0.0.1:6379> JSON.GET anotherexample $
"[[true,{\"answer\":42}]]"

 

The JSON.DEL command deletes everything you tell it to. Arrays may be managed using a subset of RedisJSON commands:

127.0.0.1:6379> JSON.SET nums $ []
OK
127.0.0.1:6379> JSON.ARRAPPEND nums $ 0
1) (integer) 1
127.0.0.1:6379> JSON.GET nums $
"[[0]]"
127.0.0.1:6379> JSON.ARRINSERT nums $ 0 -15 24
1) (integer) 3
127.0.0.1:6379> JSON.GET nums $
"[[-15,-24,0]]"
127.0.0.1:6379> JSON.ARRTRIM nums $ 1 1
1) (integer) 1
127.0.0.1:6379> JSON.GET nums $
"[[-24]]"
127.0.0.1:6379> JSON.ARRPOP nums $
1) "-24"
127.0.0.1:6379> JSON.ARRPOP nums $
1) (nil)

 

In addition to this, objects have their own commands too:

127.0.0.1:6379> JSON.SET myObject $ '{"name":"SK Rossi","lastTimeOpened":2654446300,"logInStatus": false}'
OK
127.0.0.1:6379> JSON.OBJLEN myObject $
1) (integer) 3
127.0.0.1:6379> JSON.OBJKEYS myObject $
1) 1) "myname"
   2) "lastTimeOpened"
   3) "logInStatus"

With Redis-Py

This code example demonstrates how to utilize RedisJSON in conjunction with raw Redis commands from Python using Redis-py:

import redis
import json
data = {
    'dev': 'web'
}
q = redis.Redis()
q.json().set('obj', '$', json.dumps(myData))
result = json.loads(q.json().get('obj', '$')[0])

Building on Ubuntu 20.04

For building successfully on Ubuntu 20.04, the following packages are required:

sudo apt install build-essential llvm cmake libclang1 libclang-dev cargo

 

Then, in the repository directory, make, or cargo build—release.

Loading the Module to Redis

We recommend that you use Redis v6.0 or above and that you load the module at startup by adding the following to your redis. conf file:

loadmodule /path/to/module/target/release/librejson.so

 

Replace /path/to/module/ with the actual path to the module's library in the preceding lines.

You may also use the following command-line argument syntax to have Redis load the module:

~/$ redis-server --loadmodule ./target/release/librejson.so

Frequently Asked Questions

What is RedisJSON?

RedisJSON is a fast NoSQL document storage that enables developers to create new apps.

Is RedisJSON open-source?

Redis Modules developed by Redis Ltd. (for example, RediSearch, RedisGraph, RedisJSON, RedisML, RedisBloom) are distributed under the Redis Source Available License (RSAL).

Which data-type RedisJSON implements?

RedisJSON is a Redis module that implements as a native data type ECMA-404, the JSON Data Interchange Standard.

What is the function of JSON.STRLEN and JSON.STRAPPEND?

JSON.STRLEN returns the length of the string, while JSON.STRAPPEND appends another string to it.

Conclusion

This article extensively discussed RedisJSON, JSON support in Redis stack, its implementation, and features. We hope this blog has helped you enhance your knowledge regarding JSON support in the Redis stack. After reading about the Redis Database, are you not feeling excited to read/explore more articles on this topic? Don't worry; Coding Ninjas has you covered. To learn, see Operating SystemUnix File SystemFile System Routingand File Input/Output.

You can also consider our Mern Stack Course to give your career an edge over others.

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass