Skip to Content

Scripting Example - JSON

This example demonstrates how to generate JSON using an action. A cell is updated with the generated JSON for use by a later action. The example leverages the JSON.Net library included with Vinyl.

Table Schema

Column Data Type Primary Key Auto-generate Nullable
CustomerId GUID Yes Yes No
CompanyName NVARCHAR(100) No No No
Address INTEGER No No Yes
City NVARCHAR(100) No No Yes
Region NVARCHAR(2) No No Yes
PostalCode NVARCHAR(50) No No Yes
AddressJson NVARCHAR(500) No No Yes

Note that the AddressJson column does not need to be defined on the table: it can be defined on the business object.

Script

#r "Newtonsoft.Json.dll"

using Newtonsoft.Json.Linq;

var address = new JObject(
    new JProperty("address", Row["Address"].Value),
    new JProperty("city", Row["City"].Value),
    new JProperty("region", Row["Region"].Value),
    new JProperty("postalCode", Row["PostalCode"].Value)
);

Row["AddressJson"].Value = address.ToString();