You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,7 +93,7 @@ Torque is a high-performance JSON library for Elixir using Rustler NIFs backed b
93
93
94
94
### Encoding
95
95
96
-
`encode/1` walks Elixir terms directly (no intermediate representation) and writes JSON bytes to a buffer. Supports maps (atom/binary keys), lists, numbers, booleans, nil, and jiffy-style `{proplist}` tuples.
96
+
`encode/1` walks Elixir terms directly (no intermediate representation) and writes JSON bytes to a buffer. Supports maps (atom/binary/integer keys — integer keys are stringified, since JSON object names must be strings), lists, numbers, booleans, nil, and jiffy-style `{proplist}` tuples.
|`:unsupported_type`|`encode/1`| Term has no JSON representation (PID, reference, port, …) |
193
198
|`:invalid_utf8`|`encode/1`| Binary string or map key is not valid UTF-8 |
194
-
|`:invalid_key`|`encode/1`| Map key is not an atomor binary (e.g. integer key) |
199
+
|`:invalid_key`|`encode/1`| Map key is not an atom, binary, or integer (e.g. float or tuple key) |
195
200
|`:malformed_proplist`|`encode/1`|`{proplist}` contains a non-`{key, value}` element |
196
201
|`:non_finite_float`|`encode/1`| Float is infinity or NaN (unreachable from normal BEAM code) |
197
202
|`:nesting_too_deep`|`encode/1`| Term exceeds 128 nesting levels |
@@ -286,6 +291,7 @@ MIX_ENV=bench mix run bench/torque_bench.exs
286
291
287
292
## Limitations
288
293
294
+
-**Integer map keys are lossy**: JSON object names must be strings (RFC 8259 §4), so `encode/1` stringifies integer keys and `decode/1` gives them back as binaries — `%{1 => "a"}` round-trips to `%{"1" => "a"}`. A map mixing both forms, like `%{1 => "a", "1" => "b"}`, encodes to duplicate names (`{"1":"a","1":"b"}`); RFC 8259 says names *should* be unique, and decoders resolve the collision however they choose. Jason behaves identically.
289
295
-**Nesting depth**: JSON documents nested deeper than 128 levels return `{:error, :nesting_too_deep}` from `decode/1`, `parse/1`, `get/2`, `get_many/2`, and `encode/1` rather than crashing the VM. Real-world documents are never this deep; the limit exists to prevent stack overflow in the NIF (the dirty CPU scheduler, used for inputs over 20 KB, has a small stack).
0 commit comments