-
Notifications
You must be signed in to change notification settings - Fork 360
How to transform multi layer sets in JSON strings with esProc
There is a 2-layer JSON string with multiple dynamic key values in the lower layer, excluding set/array types.
{"Games": {"key1": "value1", "key2": value2,"key3":value3}}
Now we need to transform the lower layer into a set of multiple layers.
{"Games":{"AllGames":[{"key1":["value1"]},{"key2":["value2"]},{"key3":["value3"]}]}}
SQL itself does not support multi-layer data, making it more difficult to express multi-layer sets, and the indirectly implemented code is very complex. SPL naturally supports multi-layer data and multi-layer sets:
https://try.esproc.com/splx?4JF
| A | |
|---|---|
| 1 | {"Games": {"key1": "value1", "key2": value2,"key3":value3}} |
| 2 | =E@p([A1.Games]) |
| 3 | =new(new(A2.(eval("new([~2]:"/ ~1 /")")):AllGames):Games) |
| 4 | =json(A3) |
A1: Automatically parse the multi-layer JSON string into SPL table sequence. After clicking and expanding, you can see that the upper layer is a single field record, and the lower layer is a multi-field record.




SPL Resource: SPL Official Website | SPL Blog | Download esProc SPL | SPL Source Code