Fields to JSON tutorial

This tutorial outlines how to transform data from fields to JSON. To run these actions:

  1. Navigate to the Code tab.
  2. Select API Console from the Code menu.
  3. Paste the example code into the API Console and click the Run button. 

 

Create an integration table

This action creates an integration table with 3 fields, two inputs and one output.

{
  "api":    "hub",
  "action": "createIntegrationTable",
  "params": {
    "tableName":              "TransformV2SecondStep",
    "logTransformOverwrites": false,
    "fields": [
      {
        "name": "source_varchar_field",
        "type": "VARCHAR",
        "length": 200
      },
      {
        "name": "source_integer_field",
        "type": "INTEGER"
      },
      {
        "name": "destination_json_field",
        "type": "JSON"
      }
    ],
    "transformSteps": [
      {
        "transformStepMethod": "tableFieldsToJson",
        "mapOfPropertiesToFields": [
          {
            "fieldName":  "source_varchar_field",
            "recordPath": "destination_json_field.varcharProperty"
          },
          {
            "fieldName":  "source_integer_field",
            "recordPath": "destination_json_field.integerProperty"
          }
        ]
      }
    ]
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

 

Insert Records 

This example inserts one record into both of the two input fields.

{
  "action": "insertRecords",
  "params": {
    "tableName": "TransformV2SecondStep",
    "dataFormat": "objects",
    "sourceData": [
      {
        "source_varchar_field": "Test VarChar",
        "source_integer_field": 2112
      }
    ]
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

 

View records

This example will return the records from the table

 {
  "api": "db",
  "action": "getRecordsByTable",
  "params": {
    "databaseName": "faircom",
    "tableName": "TransformV2SecondStep"
  },
  "authToken": "replaceWithAuthTokenFromCreateSession"
}

 

Response

Inspect the "destination_json_field" field to make sure the transform worked.

"data": [
   {
      "changeId": 200248,
      "create_ts": "2026-03-26T23:59:25.818000000",
      "debug": null,
      "destination_json_field": {
         "integerProperty": 2112,
         "varcharProperty": "Test VarChar"
      },
      "error": false,
      "id": 1,
      "log": null,
      "metadata": null,
      "source_integer_field": 2112,
      "source_payload": null,
      "source_varchar_field": "Test VarChar"
   }
]