10000 json: support map serialization in particular order · Issue #10606 · tarantool/tarantool · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

json: support map serialization in particular order #10606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
grafin opened this issue Sep 24, 2024 · 1 comment · Fixed by #10584
Closed

json: support map serialization in particular order #10606

grafin opened this issue Sep 24, 2024 · 1 comment · Fixed by #10584
Assignees
Labels
feature A new functionality serializers Fearutes and bugs related to built-in serializers

Comments

@grafin
Copy link
Member
grafin commented Sep 24, 2024

Similar to #9747 but for json.

Part-of TNTP-196.

Use cases (see #9747)

Main reason is to be able to order keys in json serialization in log messages with log_format = 'json'. It is crucial to have such feature to be able to setup custom log context and the log messages still printing the information in predictable order.

Implementation

We have a serializer class in src/lua/serializer.c and src/lua/serializer.h, which can accept options as second argument in encode() and decode() calls. Lets add an encode_key_order option, which can accept a table (array) of ordered keys, in the order we want them present in the encoded string.

It should work something like:

tarantool> json = require('json')
---
...

tarantool> map = {a = 1, c = 100, b = 2}
---
...

tarantool> json.encode(map)
---
- '{"b":2,"a":1,"c":100}'
...

tarantool> json.encode(map, {encode_key_order = {'a', 'b', 'c'}})
---
- '{"a":1,"b":2,"c":100}'
...

tarantool> json.encode(map, {encode_key_order = {'a', 'b'}})
---
- '{"a":1,"b":2,"c":100}'
...

tarantool> json.encode(map, {encode_key_order = {'a', 'b', 'd'}})
---
- '{"a":1,"b":2,"c":100}'
...

For already created serializer object we should be able to create a persistent ordering:

tarantool> json = require('json')
---
...

tarantool> map_1 = {a = 1, c = 100, b = 2}
---
...

tarantool> j = json.new()
---
...

tarantool> j.cfg({encode_key_order = {'a', 'b'}})
---
...

tarantool> j.encode(map_1)
---
- '{"a":1,"b":2,"c":100}'
...

tarantool> j.encode(map_1, {encode_key_order = {'c', 'b'}})
---
- '{"c":100,"b":2,"a":1}'
...

tarantool> j.encode(map_1)
---
- '{"a":1,"b":2,"c":100}'
...
@grafin grafin added the feature A new functionality label Sep 24, 2024
@grafin grafin self-assigned this Sep 24, 2024
grafin added a commit to grafin/tarantool that referenced this issue Sep 24, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Sep 24, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Sep 24, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Sep 24, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Sep 24, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Sep 24, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Sep 24, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
@Totktonada Totktonada added the serializers Fearutes and bugs related to built-in serializers label Sep 25, 2024
grafin added a commit to grafin/tarantool that referenced this issue Sep 26, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Sep 30, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Sep 30, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 2, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 3, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 14, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
@grafin
Copy link
Member Author
grafin commented Oct 18, 2024

Currently doing this:

tarantool> require('json').encode(map, {encode_key_order = {'a', 'b', 42, {"asd"}}})

Results in assertion failure:

tarantool: src/lua/serializer.c:186: void luaL_serializer_parse_encode_key_order(struct lua_State *, struct luaL_serializer *): Assertion `lua_isstring(L, -1)' failed.
Aborted (core dumped)

I think we should change this assertion into box.error similar to:

tarantool> require('json').encode({a = 1, b = 2, c = 3, d = 4, e = 5, [{'asd'}] = 6})
---
- error: table key must be a number or string
...

Will be back with. a PR update)

grafin added a commit to grafin/tarantool that referenced this issue Oct 23, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 23, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 23, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 30, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 30, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 30, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 30, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 30, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Oct 30, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Nov 1, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Nov 3, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Nov 4, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
grafin added a commit to grafin/tarantool that referenced this issue Nov 4, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes tarantool#10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
Totktonada pushed a commit that referenced this issue Nov 4, 2024
This option allows to pass an array of keys that will be used to sort
keys in maps during serialization to json. The order of the provided keys
in the resulting string will be the same as in the `encode_key_order`
array. Keys, present in maps and not included in `encode_key_order` will
be serialized after the sorted ones in arbitrary order.

Closes #10606

@TarantoolBot document
Title: A new `encode_key_order` option for json encoder introduced
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.

``` lua
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:
``` lua
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}'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new functionality serializers Fearutes and bugs related to built-in serializers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0