Exercise Web Calls in JSON Reader
Overall Goal To show how to use a web service within the JSON Reader
Demonstrates Calling a web service directly from an FME Reader
Completed Workspace Download Complete

Download Completed Advanced Task

The FME Readers support reading data from the web, so this allows the readers to call a web service to bring the data directly into the relevant reader. This is typically used with JSON or XML readers as these are the most common formats used by web services, though image readers can also be used with a WMS request for example.


1) Create a New Blank Workspace

Open FME Desktop and select New to create a new blank canvas.

New Workspace

2) Add JSON Reader

Use the quick add tool to add a JSON reader, this can be accessed by starting to JSON when the canvas area is active. As you type the dialogue below should appear.

Scroll down the list and select the JSON Reader as shown below.

Add JSON Reader

The standard JSON Reader dialogue box will appear, in the Dataset field enter the following web service URL.

https://data.smartdublin.ie/dublinbikes-api/last_snapshot/

Then in the Coord. System field choose EPSG:4326 as shown below clicking on OK once configured.

Configure JSON Reader

3) Review the Data

When the Reader adds the JSON it will automatically call the web service and scan the schema and add an appropriate Feature Type to the canvas. You'll notice that compared to the HTTPCaller in the previous exercise there are now attributes displayed as below.

review featuretype

If you select the FeatureType and select the Run To option FME will call the service and read in the data, you will see that in this case it automatically creates features for each station within the dataset rather than return a single JSON file as the HTTPCaller does.

review response

4) Create Geometry

As the data comes in as individual features it is possible to create geometries from the Latitude and Longitude values contained within the response. Add and connect a VertexCreator to the JSON feature type and set the X Value to Longitude and the Y Value to Latitude within the transformers parameters.

create vertex

5) Display Available Bikes

In order to better visualise the number of bikes available at each station we can use a scaled buffer. To do this add a Bufferer transformer connected to the VertexCreator as shown.

Add Bufferer transformer

As our data's coordinate system is WGS84 its distance units are in Degrees but we want to create our buffer in meters so in the Bufferer transformer properties set theBuffer Distance Units to Meters. Then select Open Arithmetic Editor for Buffer Distance to open the Arithmetic Editor window.

Configure JSON Reader

In the editor window enter the following expression. This will take the available bikes at each station and times that value by a constant of 10. This will create a scaled buffer based on the available number of bikes. The value of 10 is arbitrary but provides a good scale in this instance to aid visualising the data.

@Value(available_bikes)*10

Configure JSON Reader

6) Visualise the Output

Run the Bufferer transformer and view the output in the Visual Preview panel, it should look similar to the example below.

Your data will be live so will reflect the availability at the current moment in time so don't worry if yours looks a little different to the example below.

Configure JSON Reader


Advanced Task

The task above uses the JSON Reader directly however this does not allow the user to pass in parameters at run timely easily. The same approach can also be taken but using the JSON reader within the FeatureReader transformer. This allows the request URL to be built up from existing parameter or attribute values. Try replacing the above reader with a creator and FeatureReader transformer.