A JSON field was coming from a Talend route message body but other than extract JSON fields to a schema, I needed to add to the schema the topic.

I don’t know if I was blind but it took me a while to understand how to create a flow of data extracted from a JSON (coming from an MQTT subscriptions) and add to this data flow even the topic name (which finally contained the client identifier).

Note: if you need to add to your data flow the topic name from a Talend route message generated by an MQTT broker other than the message body, look at Get Topic Name on Talend Job From cMQTT Message.

First I created a schema within the tExtractJSONFields component using jsonPath. The JSON was very simple: a plain set of properties without nested object or array.

The input flow came form a tRouteInput with two fields: body (the JSON) and topic (a String).

Schema of the data flow generated by a tInputRoute with the bodu and the topic

The mapping from the input schema and the output one looks like:

tExtractJSONFields configuration

The JSON mapping is very simple but you can not a particular: the last output schema column is just the name of the topic input column without a JSON query. This field is mapped directly with the input field with the same name.

Actually I don’t know if this is a convention, a side effect or whatever, but it saved my day!

(if you can identify a documentation page where this “effect” is describe, please don’t leave me in the dark, thank you)

Leave a Reply