JsonEncode / Struct Layer
Convert struct columns into JSON string representation. Similar to Python's json.dumps(), JavaScript's JSON.stringify(), or R's toJSON(). Creates a new column with valid JSON string format.
Example transformation:
Input struct column:
user |
---|
{name: 'John', age: 30} |
{name: 'Mary', scores: [1,2]} |
After JSON encoding:
user_json |
---|
'{"name":"John","age":30}' |
'{"name":"Mary","scores":[1,2]}' |
Common applications:
- API payload preparation
- Data serialization
- Storage in text formats
- Database compatibility
- Cross-system data exchange
- Configuration storage
- Logging structured data
Note: The output is UTF-8 encoded, escaped according to JSON standards. Special characters are properly escaped, and nested structures are preserved in the JSON representation.
Table
0
0
Table
Select
columnThe struct column to encode. Supports various data types:
- Nested objects {key: value}
- Arrays [1, 2, 3]
- Mixed types {name: 'John', scores: [88, 92]}
- Null values
- Nested structures {user: {details: {age: 30}}}
Example input structures:
- Simple: {id: 1, name: 'John'}
- Nested: {user: {role: 'admin'}}
- Arrays: {tags: ['red', 'blue']}
AsColumn
nameName for the new column. If not provided, the system generates a unique name. If AsColumn
matches an existing column, the existing column is replaced. The name should follow valid column naming conventions.