Skip to content

Implement JSON.SET and JSON.GET commands #88

Description

@AlexJuca

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

  1. Path support — root-only ($) for v1, or a subset of JSONPath ($.a.b, array indexing)? Root-only is far simpler and covers most use.
  2. 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).
  3. JSON parser — vendor a small C parser (e.g. cJSON / jsmn) vs hand-roll. Affects deps and the build.
  4. Value type — add a new VALUE_ENTRY_TYPE_JSON to value_entry_t so GET/future TYPE can distinguish JSON from RAW/INT.
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions