-
Notifications
You must be signed in to change notification settings - Fork 387
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
Labels
Comments
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}' ```
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}' ```
Currently doing this:
Results in assertion failure:
I think we should change this assertion into
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
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()
anddecode()
calls. Lets add anencode_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:
For already created serializer object we should be able to create a persistent ordering:
The text was updated successfully, but these errors were encountered: