How to ignore not known json fields in tHMap processing

One Star

How to ignore not known json fields in tHMap processing

I have a job that calls REST API, retrieves json and transforms it using tHMap.

I faced the problem: when provider adds some fields to json returned by API (I do not use those fields and can ignore them), i got an exception like:
: com.oaklandsw.transform.runtime.Trace - line 15 null out$/Root emit:  ''
Exception in component tHMap_1
java.lang.Exception: Overall: Fatal
1: Info - Executing map. (328)
 Map: /MARKETPLACE/Maps/Jobs/test/testEscapeProblem  Properties: {}
2: Fatal - An element appeared in a JSON document that was not present in the structure. If this element is a JSON value, consider selecting the Name is Value element property.  (1401)
 Enclosing Element : Map: Maps/Jobs/test/testEscapeProblem.xml - Map Element: in$/Root
 somethingelse
3: Fatal - There was a problem with a Source using an I/O expression. The details are in the status item before this one. (344)
 I/O - IO Reader: Map Element: <root>  <Unknown function> Rep: JSON id: 0x6d3a388c URL: <map/struct source>

This is because json structure in tHMap is based on sample json:
{
"element": "value"
}

And the json I am transforming is:
{
"element": "val1",
"somethingelse": "val2"
}

So "somethingelse" key is missing in my structure. I don't want to add "somethingelse" key to my structure because the point here it to be forward compatible in meaning I don't want to fail if provider adds some fields to his json.
Is there any way to configure tHMap not to fail in such case?
Moderator

Re: How to ignore not known json fields in tHMap processing

Hi,
Could you please indicate on which build version you got this issue? Are you using tXMLMap in your work flow?
Screenshots of your job setting will be preferred.
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: How to ignore not known json fields in tHMap processing

I'm using Talend Data Management Platform 6.0.1.20151110_1633_patch.
I'm not using tXMLMap. Only tHMap component.
I attach screenshots of sample job showing this issue along with configuration of thMap component and structure



 
And input json file that causes error:
{
"element": "val1",
"somethingelse": "val2"
}
Four Stars

Re: How to ignore not known json fields in tHMap processing

I'm facing a similar issue with tHMap and my json file, i.e. the json file sometimes has extra fields that I don't care about.

I'm getting the same message:

Warning - An element appeared in a JSON document that was not present in the structure. If this element is a JSON value, consider selecting the Name is Value element property.  (1401) 

 

Anyone have any ideas on how to resolve?