A new `encode_key_order` option for json encoder introduced
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 15
- Forks
- 49
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 3
Description
Product: Tarantool
Since: 3.3.0
This option allows to specify the order in which the keys of object will be
serialized. To specify a particular order, it is possible to pass an
array of the keys, and resulting JSON string will contain the provided
keys in the specified order, while other present keys of an object will
be present after in some arbitrary order.
map = {a = 1, c = 100, b = 2}
require('json').encode(map)
-- returns '{"b":2,"a":1,"c":100}'
require('json').encode(map, {encode_key_order = {'a', 'b'}})
-- returns '{"a":1,"b":2,"c":100}'
require('json').(map, {encode_key_order = {'a', 'b', 'd'}})
-- returns '{"a":1,"b":2,"c":100}'
For a persistent serializer object a persistent ordering can be defined:
map_1 = {a = 1, c = 100, b = 2}
j = require('json').new()
j.cfg({encode_key_order = {'a', 'b'}})
j.encode(map_1)
-- returns '{"a":1,"b":2,"c":100}'
j.encode(map_1, {encode_key_order = {'c', 'b'}})
-- returns '{"c":100,"b":2,"a":1}'
j.encode(map_1)
-- returns '{"a":1,"b":2,"c":100}'
Requested by @grafin in https://github.com/tarantool/tarantool/commit/8806b7b561d58d1cef79e6c9c723827f4ce67ed8.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No target documentation file is named; first locate the JSON encoder and persistent serializer reference in the Tarantool docs. Document encode_key_order for json.encode and json.new().cfg, including the provided ordering examples and the behavior of unspecified keys; done when both per-call and persistent configurations are covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100