Skip to content

Commit 99aceac

Browse files
committed
Explicitly document json.encode accepting __order
1 parent 087af76 commit 99aceac

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/Runtime Environment/JSON.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ print(json.encode(data, true))
3232
--> }
3333
```
3434

35+
Because Lua tables do not have order guarantees, you can add an `__order` field to fix the order:
36+
```pluto
37+
local t = {
38+
__order = { "a", "b", "c" },
39+
a = 1,
40+
b = 2,
41+
c = 3
42+
}
43+
print(require"json".encode(t)) -- {"a":1,"b":2,"c":3}
44+
```
45+
3546
The `json.null` value — assuming you did `local json = require("json")` — can be used to encode JSON null values.
3647
```pluto
3748
local json = require("json")

0 commit comments

Comments
 (0)