feat: split json.lua and add encode_canonical #15

Closed
opened 2026-05-03 06:33:03 +02:00 by michael · 0 comments
Owner

Goal

Split json.lua (currently >250 lines) into focused sub-files and add
encode_canonical for stable cross-instance hashing.

Required by DAW/daw-modul-federation-sync for payload_hash computation.

Changes

Split into:

  • json_encode.lua -- encoding logic (all three tiers)
  • json_decode.lua -- decoding logic (all three tiers)
  • json.lua -- thin wrapper, loads both, exposes encode, decode, encode_canonical

Add encode_canonical(value):

  • Always uses sorted-keys pure-Lua encoder, independent of active backend
  • Returns deterministic JSON string suitable for hashing
  • Used via json.encode_canonical(payload) before crypto.hash_string()

Acceptance Criteria

  • json.lua split into json_encode.lua + json_decode.lua + json.lua wrapper
  • json.encode_canonical available and backend-independent
  • All existing tests pass
  • New tests for encode_canonical (key order, nested tables, arrays)
## Goal Split `json.lua` (currently >250 lines) into focused sub-files and add `encode_canonical` for stable cross-instance hashing. Required by DAW/daw-modul-federation-sync for `payload_hash` computation. ## Changes Split into: - `json_encode.lua` -- encoding logic (all three tiers) - `json_decode.lua` -- decoding logic (all three tiers) - `json.lua` -- thin wrapper, loads both, exposes `encode`, `decode`, `encode_canonical` Add `encode_canonical(value)`: - Always uses sorted-keys pure-Lua encoder, independent of active backend - Returns deterministic JSON string suitable for hashing - Used via `json.encode_canonical(payload)` before `crypto.hash_string()` ## Acceptance Criteria - [ ] json.lua split into json_encode.lua + json_decode.lua + json.lua wrapper - [ ] `json.encode_canonical` available and backend-independent - [ ] All existing tests pass - [ ] New tests for `encode_canonical` (key order, nested tables, arrays)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-lua-common#15
No description provided.