JSON (JavaScript Object Notation) Reader/Writer

Licensing options for this format begin with FME Professional Edition.

FME can read and write data in the JSON (JavaScript Object Notation) format.

JSON is a simple structured text format. It is designed to be easy to script and read, and to be easily integrated into JavaScript applications. Like the GeoJSON (Geographic JavaScript Object Notation) Reader/Writer, spatial data in JSON is identified using key/value pairs. However, unlike GeoJSON, JSON does not define a standard schema of key names. This limitation makes JSON less suitable than GeoJSON for applications that retrieve spatial data from multiple sources.

The paragraph below gives an overview of JSON syntax. For detailed information about the JSON format, see http://www.json.org.

Overview of JSON Syntax

JSON syntax uses objects and arrays.

A JSON object is a pair of braces containing key/value pairs separated by commas, with a colon between each key and value. Keys are an unordered set of strings; each key in an object is unique, and they can be specified in any order. An object can have any number of key/value pairs, including zero. A sample JSON object is:

{
	“key with string value”:”this is a string value”,
	“key with exponential value”:-59.45E-4,
	“key with null value”:null,
	“key with boolean value”:true,
	“key with array value”:[ false, 12, 56.82, { “key”:”value” } ],
	“key with object value”:{}
}

A JSON array is an ordered set of values separated by commas. A value can be an object, an array, a string, a number (integral, decimal, or exponential), a Boolean, or the literal value null. An array can have any number of values, including zero. A sample JSON array is:

[
	12,
	“a string value”,
	56.3e6,
	null,
	false,
	[ 1, 2, 3, {} ]
]

Using JSON Datasets with FME

Specifying a Coordinate System

By default, coordinate systems in JSON are specified using the json_ogc_wkt_crs key and OGC WKT text.

If you are using a different key name in your reader or writer datasets, the default can be overwritten in FME Workbench when specifying the reader or writer parameters. You can access these parameters when you add the reader or writer to a new workspace, or from the Navigator pane in an existing workspace.

Quotations in the WKT text must be escaped with backslashes.

{
	“json_featuretype”:”SampleJSONFeature”,
	“json_ogc_wkt_crs”:”GEOCS[\”WGS84 Lat/Long’s, Degrees, -180 ==>	\
		+180\”,DATUM[\”WSG_1984\”,SPHEROID[\”World Geodetic System of	\
		1984\”,6378137,298.257223563],AUTHORITY[\”EPSG\”,\”6326\”]],  \
		PRIMEM[\”Greenwich\”,0],UNIT[\”degree\”,0.0174532925199433], \
		AUTHORITY[\”EPSG\”,\”4326\”]]”
	“json_geometry”:”LINESTRING(45.3 56.89, 85.63 96.73, 12.61 91.38)”
}

Note: FME supports features without a coordinate system assigned to them. If a coordinate system is specified for the reader in FME Workbench that differs from one specified in the reader dataset, the coordinate system specified in Workbench overrides the one specified in the dataset.

Specifying Geometry

By default, JSON feature types are identified using the json_featuretype key, and feature geometry is specified using the json_geometry key.

If you are using different key names in your reader or writer datasets, these defaults can be overwritten in FME Workbench when specifying the reader or writer parameters. You can access these parameters when you add the reader or writer to a new workspace, or from the Navigator pane in an existing workspace.

Geometry key/value pairs can be specified in GeoJSON or OGC WKT text. In either case, you must specify the type of geometry that the reader or writer should attempt to interpret. In GeoJSON, possible values of the type key are Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon.

The reader and writer also allow for attribute-only datasets that contain no geometry.

Example 1 (GeoJSON) :

{
	“json_featuretype”:”SampleJSONFeature”,
	“json_geometry”:
	{
		“type”:”LineString”,
		“coordinates”:[ [45.3,56.89], [85.63,96.73], [12.61,91.38] ]
	}
}

Example 2 (OGC-WKT):

{
	“json_featuretype”:”SampleJSONFeature”,
	“json_geometry”:”LINESTRING(45.3 56.89, 85.63 96.73, 12.61 91.38)”
}