Question

How to create a JSON upload body for HTTPCaller


Normally I use input from a JSON-file directly as JSON upload body for HTTPCaller. Now I need to do the same from reading an Oracle table, So how do I build the upload body, so that it looks exactly the same (in an easy way)? Have tried with no luck, so please provide an example, if possible.

Example of a simple JSON structure wanted.

{

"vandstiktype":

{

"id": 1,

"description": "Byggevandsstik og måler",

"explanation": null

},

"maalerAnsoegning":

{

"antalMaalere": 0,

"maalertype":

{

"id": 1,

"description": "Vandmåler ved egen boring",

"explanation": null

}

},

"aeldreEllerUngdomsBolig": false

}


5 replies

Userlevel 2
Badge +17

I thinnk you can use the JSONTemplater transformer to build a JSON text (i.e. upload body) from the attributes in the input features, which have been read from the Oracle table.

How to configure the transformer, depends on schema of the source table and how you need to map the attributes to member objects in the destination JSON.

Thanks takashi, My idea too, but I have tried it with no luck.

I guess I'm not understanding the JSONTemplater correct. That's why, I would very much like to see a real FME-example on how to use the JSONTemplater.

Userlevel 2
Badge +17

For example, assuming that the input feature has these attributes,

Attribute NameAttribute Valueattr11attr2abcattr3xyz

the JSONTemplater with this template expression

{
    "a1" : fme:get-attribute("attr1"),
    "a2" : fme:get-attribute("attr2"),
    "a3" : fme:get-attribute("attr3")
}

generates this JSON text.

{
   "a1" : 1,
   "a2" : "abc",
   "a3" : "xyz"
}

Here is another example.

https://knowledge.safe.com/questions/82580/json-from-oracle-query.html

@takashi. Thx a lot. Exactly what I was looking for. A simple example, so I at least get the notation correct, even if my JSON structure will be more complex with several nested structures.

However trying your example on real data, gives me an error in the templater, before I run it. "Attributes does not exist" even if the names are copied directly from the Oracle reader. I'll do some more testing.

@takashi, Hi again. Now it works, by saying "No" to "Validate Attribute" - at least for the JSON structures tried so far. Thanks a lot for your help.

Reply