Basic
Convert array of objects
Overview
With this BLOCK, you can convert the data within each element of an array. You won’t be asked for the pre-conversion data types for each element in the array, but each element in the post-conversion array will become an Object. During the conversion, the BLOCK will use a set of conversion rules you define on each element in the array. The number of elements in the pre and post-conversion arrays will stay the same.
The following is an example of a conversion using this BLOCK (JSON format array of objects):
- Before converting:
[ { "first_name": "Jane", "last_name": "Austen", "book1": "Pride and Prejudice", "book2": "Sense and Sensibility", "book3": "Mansfield Park" }, { "first_name": "Mark", "last_name": "Twain", "book1": "Adventures of Huckleberry Finn", "book2": "The Adventures of Tom Sawyer", "book3": "A Connecticut Yankee in King Arthur's Court" }, { "first_name": "William", "last_name": "Shakespeare", "book1": "Hamlet", "book2": "Macbeth", "book3": "Romeo and Juliet" } ]
- After conversion:
[ { "name": "Jane Austen", "masterpieces": [ "Pride and Prejudice", "Sense and Sensibility", "Mansfield Park" ], "language": "English" }, { "name": "Mark Twain", "masterpieces": [ "Adventures of Huckleberry Finn", "The Adventures of Tom Sawyer", "A Connecticut Yankee in King Arthur's Court" ], "language": "English" }, { "name": "William Shakespeare", "masterpiece": [ "Hamlet", "Macbeth", "Romeo and Juliet" ], "language": "English" } ]
The following shows specifically how the first element in the array was converted:
As you can see, you can use this BLOCK to do things like combine values or add new values. While not shown in the above example, you can also delete, or omit, values from the pre-conversion array.
To perform this kind of conversion, you must set conversion rules for the post-conversion object.
For the above example, the conversion rules are as follows:
You must set the key, value type, and value, for each key:value pair in the post-conversion object.
You can select from the following eight types for the value type:
Type | Explanation |
---|---|
String |
Designates the value as a string. You can enter a key from the pre-conversion object within |
String (old) |
Designates the value as a string. This is mostly the same as the String type explained above, but you cannot use % format characters. |
Integer |
Designates the value as an integer. |
Float |
Designates the value as a float. |
Boolean |
Designates the value as a Boolean |
Variable |
Designates the value as a variable.
|
Object |
Designates the value as an object. |
Array |
Designates the value as an array. |
Properties
Property | Explanation |
---|---|
BLOCK name | Configure the name displayed on this BLOCK. |
Source variable |
Designate the variable that contains array data to be converted. |
Results variable |
Designate the variable that will contain the newly-converted array of objects. |
Conversion rules |
Define the format of the post-conversion object. |
BLOCK memos | Make notes about this BLOCK. |