transformations:constructjson
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
transformations:constructjson [2020/01/11 15:44] – dmitry | transformations:constructjson [2025/02/10 18:55] (current) – revise to 2025 format craigt | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Construct | + | {{ transformations: |
+ | ======CONSTRUCT | ||
+ | Category: Transform / Web\\ | ||
- | This action constructs a [[https:// | + | \\ |
- | * Object per row, array from objects | + | =====Description===== |
- | * Array per column | + | This action constructs a [[https:// |
- | A constructed | + | \\ |
+ | =====Action settings===== | ||
+ | ==== Mode: " | ||
+ | In this mode, each row of the source dataset is used to construct a flat JSON object | ||
- | ==== Mode " | + | If the source dataset |
- | In this mode, each row of the source dataset | + | |
- | ^ Name ^ Kingdom | + | \\ |
- | | Rabbit |Animalia | Chordata | Vertebrata | Mammalia | + | ==== Mode: "Array per column" |
+ | In this mode, the source dataset is converted into a new dataset in which values of each column are rolled up into a JSON array. See Example #3, below. | ||
- | is constructed | + | \\ |
+ | =====Remarks===== | ||
+ | ====Data type conversion==== | ||
+ | EasyMorph data types are converted to JSON types as follows: | ||
+ | |||
+ | ^ EasyMorph ^ Example ^ JSON ^ Example ^ | ||
+ | | Text | ABC | string | ||
+ | | Number | ||
+ | | Number (formatted as date) | ||
+ | | Boolean | ||
+ | | Empty | ||
+ | | Error | #Division by zero | Fails to convert | ||
+ | |||
+ | Note that the action fails if the source dataset contains an error value. | ||
+ | |||
+ | \\ | ||
+ | ====Nesting JSON objects==== | ||
+ | EasyMorph automatically detects if a text value is already a JSON object or a JSON array. In this case, the text value is inserted verbatim, i.e. **without** wrapping in double-quotes. This feature allows creating complex hierarchical JSON objects that nest other JSON objects. For instance, converting the table below: | ||
+ | |||
+ | ^ Track ^ Country | ||
+ | | Circuit Gilles Villeneuve | ||
+ | |||
+ | would produce | ||
+ | |||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | Notice that " | ||
+ | |||
+ | \\ | ||
+ | =====Examples===== | ||
+ | ====Example #1==== | ||
+ | > | ||
+ | |||
+ | ===Before (source table)=== | ||
+ | ^ Name ^ Kingdom | ||
+ | | Rabbit |Animalia | Chordata | Mammalia | ||
+ | ===After (result table)=== | ||
< | < | ||
{ | { | ||
Line 20: | Line 72: | ||
" | " | ||
" | " | ||
- | " | ||
" | " | ||
- | " | ||
- | " | ||
} | } | ||
</ | </ | ||
- | If the source dataset contains multiple rows, they will be converted into an array of JSON objects where each object corresponds to one row. Example: | + | ===Action parameters=== |
+ | >Mode: | ||
+ | \\ | ||
+ | ====Example #2==== | ||
+ | >Create a flat JSON object from the multi-row tabular dataset. | ||
+ | |||
+ | ===Before (source table)=== | ||
^ ID ^ Name ^ | ^ ID ^ Name ^ | ||
| 1 | Apple | | | 1 | Apple | | ||
| 2 | Orange | | | 2 | Orange | | ||
- | Result: | + | ===After (result table)=== |
< | < | ||
[ | [ | ||
Line 45: | Line 100: | ||
} | } | ||
] | ] | ||
- | | ||
</ | </ | ||
- | ==== Mode "Array per column" | + | ===Action parameters=== |
- | In this mode the source dataset is converted into a new dataset in which values of each column are rolled up into a JSON array. For instance the table from the example above would be converted into the following table: | + | >Mode: |
+ | \\ | ||
+ | ====Example #3==== | ||
+ | >Convert the source table into a dataset in which values of each column are rolled up into a JSON array. | ||
+ | ===Before (source table)=== | ||
+ | ^ ID ^ Name ^ | ||
+ | | 1 | Apple | | ||
+ | | 2 | Orange | | ||
+ | |||
+ | ===After (result table)=== | ||
^ ID ^ Name ^ | ^ ID ^ Name ^ | ||
| [1,2] | [Apple, | | [1,2] | [Apple, | ||
+ | ===Action parameters=== | ||
+ | >Mode: Array per column | ||
- | ==== Data type conversion ==== | ||
- | EasyMorph data types are converted to JSON types as follows: | ||
- | ^ EasyMorph ^ Example ^ JSON ^ Example ^ | ||
- | | Text | ABC | string | ||
- | | Number | ||
- | | Number (formatted as date) | 2020-Jan-10 | ||
- | | Boolean | ||
- | | Empty | ||
- | | Error | #Division by zero | Fails to convert | ||
- | Note that the action fails if the source dataset contains an error value. | + | \\ |
- | + | =====Community examples===== | |
- | ==== Nesting JSON objects | + | * [[https:// |
- | EasyMorph detects if a text value already is a JSON object or JSON array. In this case, such text value is inserted verbatim, **without** wrapping with double quotes. This feature allows creating complex hierarchical | + | |
- | + | * [[https://community.easymorph.com/ | |
- | ^ Track ^ Country | + | * [[https:// |
- | | Circuit Gilles Villeneuve | + | * [[https:// |
- | + | ||
- | would produce the following JSON: | + | |
- | < | + | \\ |
- | { | + | ===== See also ===== |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | } | + | |
- | </ | + | |
- | Notice that Location is inserted as a JSON object, not as text. Field " | + | |
- | + | ||
- | ==== See also ==== | + | |
- | * [[https:// | + | |
* [[transformations: | * [[transformations: | ||
- | * [[syntax: | + | * [[syntax: |
transformations/constructjson.1578775446.txt.gz · Last modified: 2020/01/11 15:44 by dmitry