Files
-
- 10 KB
- Download
Introduction
The JSON writer converts features into a JSON file. In FME 2026.2 and later, the JSON writer can write nested objects and arrays. Before FME 2026.2, it could only write flat key/value pairs.
In this article, you will write Vancouver public art data to JSON. In Part 1, you will write each art installation as an object with a nested location object. In Part 2, you will group the art installations by neighborhood and write each group as an array of objects.
For an overview of the JSON methods in FME 2026.2 and later, see Writing JSON in FME 2026.2 and Later. For FME 2026.1 and earlier, see Writing JSON. If the JSON must be stored in an attribute instead of a file, see Building JSON with the JSONObjectBuilder and JSONAppender.
Requirements
FME Form 2026.2 or later.
The Nested Output parameter and the JSON writer attribute schema are not available in earlier versions.
Step-by-Step Instructions
To follow along, download PublicArt.xlsx from the Files section of this article. The workbook contains six sheets. Each sheet lists the public art installations in one Vancouver neighborhood.
Part 1: Write Nested Objects
In Part 1, you will rename attributes to write each art installation's coordinates inside a location object.
1. Open FME Workbench and Add a Microsoft Excel Reader
Open FME Workbench and start a new workspace. On the top menu, click Add Reader. In the Add Reader dialog:
- Format: Microsoft Excel
- Dataset: PublicArt.xlsx
- Workflow Options: Single Merged Feature Type
The Microsoft Excel reader can read each sheet as a separate feature type. The Single Merged Feature Type option reads all six sheets into one feature type. Each feature keeps its sheet name as its feature type. You use this value in the next step to add the neighborhood to each feature.
2. Restructure the Attributes With an AttributeManager
Add an AttributeManager or an AttributeRenamer to the canvas and connect it to the reader feature type. Double-click the transformer and set the following:
-
Rename Attribute:
- Input Attribute: fme_feature_type
- Output Attribute: neighborhood
-
Rename Attribute:
- Input Attribute: Name
- Output Attribute: name
-
Rename Attribute:
- Input Attribute: Title
- Output Attribute: title
-
Rename Attribute:
- Input Attribute: Longitude
- Output Attribute: location.longitude
-
Rename Attribute:
- Input Attribute: Latitude
- Output Attribute: location.latitude
The dot in location.longitude and location.latitude tells the JSON writer to write both values inside one object named location.
3. Add a JSON Writer
On the toolbar, click Add Writer. In the Add Writer dialog:
- Format: JSON (JavaScript Object Notation)
- Dataset: PublicArt_Nested.json
- Feature Type Definition: Automatic Attributes
In the Parameters dialog:
- JSON Document Structure: Array of feature objects
- Write Feature Type: No
- Write Geometry: No
- Nested Output: Yes
- Formatting Type: Pretty Print
In the Feature Type dialog, set Feature Type Name to PublicArt and click OK.
Connect the AttributeManager Output port to the PublicArt writer feature type.
4. Review the Writer Attribute Types
Double-click the PublicArt writer feature type and click the User Attributes tab. In FME 2026.2 and later, each JSON attribute has a data type. The data type controls how the value is written, for example, as a number or as a string. Confirm the following:
-
Attribute Definition: Automatic
- neighborhood: string
- name: string
- title: string
- location.longitude: float
- location.latitude: float
5. Run the Workspace and Inspect the Output
Enable Data Caching and run the workspace. Once the run is complete, open PublicArt_Nested.json in a text editor. The file contains one object per art installation. The coordinates are nested as an array in a location object:
[
{
"neighborhood" : "Downtown",
"name" : "Harbour Centre Parkade",
"title" : "The Belonging Action",
"location" : {
"longitude" : -123.110097741722,
"latitude" : 49.2837806793832
}
},
{
"neighborhood" : "Downtown",
"name" : "Harbour Centre Parkade",
"title" : "The Belonging Action",
"location" : {
"longitude" : -123.110029006403,
"latitude" : 49.28373217091
}
},
...
]Part 2: Write Arrays of Objects
Part 1 wrote one object for each art installation, so the neighborhood name repeats in every object. A more useful structure writes one object for each neighborhood, with an array of its art installations. In this part, you use an Aggregator to create a list attribute, then write the list as an array.
1. Group the Features With an Aggregator
Add an Aggregator to the canvas and connect it to the AttributeManager Output port. The AttributeManager now connects to both the PublicArt writer feature type and the Aggregator. Double-click the Aggregator and set the following:
- Group By: neighborhood
- Accumulation Mode: Drop Incoming Attributes
-
Generate List: Enabled
- List Name: artworks
- Add to List: Selected Attributes
- Selected Attributes: name, title, location.longitude, location.latitude
Click OK. The Aggregator outputs one feature for each neighborhood. Each feature has a list attribute with one element for each art installation—for example, artworks{0}.title and artworks{1}.title.
2. Add Another JSON Writer
Add another writer. In the Add Writer dialog:
- Format: JSON (JavaScript Object Notation)
- Dataset: PublicArt_ByNeighborhood.json
- Feature Type Definition: Automatic Attributes
-
Parameters:
- JSON Document Structure: Array of feature objects
- Write Feature Type: Uncheck
- Write Geometry: Uncheck
- Nested Output: Yes
- Formatting Type: Pretty Print
Click OK. In the Feature Type dialog, set Feature Type Name to Neighborhoods and click OK. Connect the Aggregator Aggregate port to the Neighborhoods writer feature type.
The curly braces in artworks{} tell the JSON writer to write an array. The dot after the curly braces tells the writer that each element in the array is an object. The second dot in location.longitude, creates a nested object inside each element.
3. Run the Workspace and Inspect the Output
Run the workspace. Once the run is complete, open PublicArt_ByNeighborhood.json in a text editor. The file contains one object for each neighborhood. Each object contains an array of art installations:
[
{
"neighborhood": "Downtown",
"artworks": [
{
"name": "Harbour Centre Parkade",
"title": "The Belonging Action",
"location": {
"longitude": -123.110097741722,
"latitude": 49.2837806793832
}
},
{
"name": "Chinese Cultural Centre",
"title": "China Gate",
"location": {
"longitude": -123.103282272368,
"latitude": 49.2797561341325
}
},
...
]
},
{
"neighborhood": "Strathcona",
"artworks": [
...
]
},
...
]Additional Resources
- Writing JSON in FME 2026.2 and Later [Article]
- Writing JSON [Article]
- Building JSON with the JSONObjectBuilder and JSONAppender [Article]
- Reading JSON [Article]
- JSON (JavaScript Object Notation) Writer Parameters [FME Documentation]
- Aggregator [FME Documentation]
Data Attribution
The data used here originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.