Skip to content

Working With JSON Data

The Valkey JSON module provides an efficient way to store and manipulate structured data. With GLIDE, Valkey modules are supported as built-in APIs, allowing you to interact with JSON module commands through dedicated client methods.

Before using a module, including the supported modules, it will need to be loaded into Valkey. See Modules Introduction on how to load modules into your Valkey service.

For more on version requirements, see our introduction on Modules API.

import glide.api.GlideClient;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.configuration.NodeAddress;
import glide.api.commands.servermodules.Json;
// Both standalone and cluster mode are supported
GlideClientConfiguration config = GlideClientConfiguration.builder()
.address(NodeAddress.builder().host("localhost").port(6379).build())
.build();
try (GlideClient client = GlideClient.createClient(config).get()) {
String key = "testKey";
String path = "$";
String jsonValue = "{\"a\": 1.0, \"b\": 2}";
CompletableFuture<String> setResponseFuture = Json.set(client, key, path, jsonValue);
String setResponse = setResponseFuture.get(); // "OK"
assert setResponse.equals("OK");
CompletableFuture<String> getResponseFuture = Json.get(client, key).get();
String getResponse = getResponseFuture.get(); // jsonValue
assert getResponse.equals("{\"a\": 1.0, \"b\": 2}");
}

For more details on the JSON module, see the Valkey JSON topic.