General information
Brick converts input data into a dictionary followed by JSON serialization format.
Description
Brick Locations
Bricks → Data Manipulation → Prepare JSON
Brick Parameters
- Orient
- dict Standard Python format: {key: {index1: value1, index2: value2, …}, …}, where key indicates a data frame column, and the value is a dictionary, constructed as ‘index: value’ pairs.
- list
- split
- records
- index
Indication of the JSON format we expect to convert to. This field is obligatory for any setting selected. Users can choose one of the presented formats:
Standard Python format: {key: [value1, value2, value3, …], …}, where key indicates a data frame column, and the value is the list of corresponding column values.
Dictionary in such format → {”index”: [index1, index2, …], “columns”: [column_name1, column_name2, …], ‘”data”: [[col1_value1, col2_value1, …], [col1_value2, col2_value2, …], …]}
List in such format → [{column_name1: value11, column_name2: value12, …}, {column_name1: value21, column_name2: value22, …} …], where the dictionaries inside are the data frame values for each row.
Dictionary in such format → {index1: {column_name1: value1, column_name2: value2, …}, …}.
- Define key
- Key type
- column
- key
- Key name
An optional boolean parameter, that provides a possibility to control the structure of created JSON. If turned off default name for the column will be “args”
If Define key option is chosen, then there are two more additional parameters to structure your JSON:
Parameter to choose whether the user option is placed as a column or as a key.
Modifies output column name.
Modifies output dictionary in a form {key: value} with key as the Key name and the value as a JSON, built in a specified way.
Parameter for setting key value that will be used as column or key in converted JSON.
Brick Inputs/Outputs
- Inputs
Brick takes the dataset.
- Outputs
Brick returns constructed JSON with a specified column name or default name of a column - “args”.
Example of usage
Let’s look at some simple examples of Prepare JSON brick usage.
The input dataset to the brick has the following structure:
We can form a JSON by connecting the dataset directly to the brick.
First, we select the ‘dict’ option with no key defined and run the pipeline.
As a result, we get the following output:
In the same way, we can use the other options.
list:
split:
records:
index:
If we check the ‘Define key’ flag, we choose column/key in the ‘Key type’.
Here, for instance, the column in the ‘Key type’ changes the output dataset’s column name into ‘abc’.
However, if we select key, we will get a different structure of the JSON.
As a more advanced example, we can take a part of a blockchain project that is running on Datrics.
Here we are using Prepare JSON brick twice because we need to structure our data on different levels. As an input, we have only multiplier and decimals columns.
Then we specify arguments in Prepare JSON brick in the following way:
As a result, we have:
Then we perform some basic data manipulations and move to another Prepare JSON brick, where we configure it in the following way:
In the output of this brick we get: