Summary
Add JSON.SET and JSON.GET commands so fkvs can store and retrieve JSON documents, similar to RedisJSON.
Motivation
fkvs has no JSON support today — the only way to store JSON is to SET the serialized string as an opaque blob, which gives no field addressing, validation, or partial updates.
Scope (minimum)
JSON.SET <key> <path> <json> — store/replace JSON at a path
JSON.GET <key> [path] — retrieve the document or a subtree
Decisions to make before implementation
- Path support — root-only (
$) for v1, or a subset of JSONPath ($.a.b, array indexing)? Root-only is far simpler and covers most use.
- Storage model — store the parsed document tree (fast path access, more memory) vs store validated raw text and re-parse on path
GET (simpler, slower path ops).
- JSON parser — vendor a small C parser (e.g. cJSON / jsmn) vs hand-roll. Affects deps and the build.
- Value type — add a new
VALUE_ENTRY_TYPE_JSON to value_entry_t so GET/future TYPE can distinguish JSON from RAW/INT.
- Protocol limit — the binary framing uses a 2-byte length prefix (core capped at 65535 bytes), so a single JSON doc must fit in one frame. Decide whether to raise this or document the limit.
Proposed v1 (minimal)
- Root-path only:
JSON.SET k $ <json> validates and stores; JSON.GET k returns the doc.
- Validate-on-write: parse to confirm well-formed JSON, store as a new JSON-typed value. No field addressing yet.
- Register
CMD_JSON_SET / CMD_JSON_GET, add handlers, add VALUE_ENTRY_TYPE_JSON.
- Follow-up issue for path addressing (
$.a.b, array indices) once v1 lands.
Acceptance criteria
JSON.SET k $ '{"a":1}' stores; JSON.GET k returns {"a":1}.
- Malformed JSON is rejected with an error reply.
- Integration tests cover set / get / overwrite / malformed.
- Benchmark numbers captured for comparison with the redis-stack
JSON.SET results above.
Relevant code
- Command registration:
src/commands/server/server_command_handlers.c (register_command, init_command_handlers)
- Command IDs:
src/commands/common/command_defs.h
- Value types:
src/core/hashtable.h (VALUE_ENTRY_TYPE_*)
- Protocol framing:
src/networking/networking.c
Summary
Add
JSON.SETandJSON.GETcommands so fkvs can store and retrieve JSON documents, similar to RedisJSON.Motivation
fkvs has no JSON support today — the only way to store JSON is to
SETthe serialized string as an opaque blob, which gives no field addressing, validation, or partial updates.Scope (minimum)
JSON.SET <key> <path> <json>— store/replace JSON at a pathJSON.GET <key> [path]— retrieve the document or a subtreeDecisions to make before implementation
$) for v1, or a subset of JSONPath ($.a.b, array indexing)? Root-only is far simpler and covers most use.GET(simpler, slower path ops).VALUE_ENTRY_TYPE_JSONtovalue_entry_tsoGET/futureTYPEcan distinguish JSON fromRAW/INT.Proposed v1 (minimal)
JSON.SET k $ <json>validates and stores;JSON.GET kreturns the doc.CMD_JSON_SET/CMD_JSON_GET, add handlers, addVALUE_ENTRY_TYPE_JSON.$.a.b, array indices) once v1 lands.Acceptance criteria
JSON.SET k $ '{"a":1}'stores;JSON.GET kreturns{"a":1}.JSON.SETresults above.Relevant code
src/commands/server/server_command_handlers.c(register_command,init_command_handlers)src/commands/common/command_defs.hsrc/core/hashtable.h(VALUE_ENTRY_TYPE_*)src/networking/networking.c