Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

JoltTransformation unable to marshal json

Highlighted

JoltTransformation unable to marshal json

New Contributor

Unable to solve this issue.

87382-capture.png

The process works with the Advance editor

87383-jolt.png

The JOLT

[{
    "operation": "shift",
    "spec": {
      "@.source": "header.source",
      "@.author": "header.author",
      "@.publishedAt": "header.date",
      "@.title": "header.title",
      "@.description": "header.description",
      "@.urlToImage": "header.image",
      "@.url": "header.url",
      "@": "source"
    }
},
  {
    "operation": "default",
    "spec": {
      "triples":{},
      "header": {
        "id":"${uuid}",
        "type": "News",
        "ingestMethod": "NiFi",
        "injestionMethod" : "${methodName}",
        "injestionUrl" : "${url}${searchQuery}${apiKey}${fromDate}${domains}",
        "injestDate":"${now()}"
      }
    }
}
]

the feed coming from a JsonSplit

{
"source": {
"id": "abc-news-au",
"name": "ABC News (AU)"
},
"author": "ABC Radio National",
"title": "The Talented Mr Daly",
"description": "Peter Daly projects confidence and success. He wears gold rings, gold cufflinks, and a gold watch. The market, he says, is his backyard and he knows it \"damn well\". But the 59-year-old is actually in a world of trouble. The corporate watchdog, ASIC, accuses h…",
"url": "http://www.abc.net.au/radionational/programs/backgroundbriefing/the-talented-mr-daly/10158316",
"urlToImage": "http://www.abc.net.au/radionational/image/10158320-1x1-700x700.jpg",
"publishedAt": "2018-08-25T22:05:00Z"
}
2 REPLIES 2

Re: JoltTransformation unable to marshal json

New Contributor

Hey Lee, did you figure something out with this. I am having the exact same issue on version 1.6.x . Thanks

Re: JoltTransformation unable to marshal json

New Contributor

Lee, all,

We tracked down the issue to an attribute variable I was using to put into the json. It had unescaped/hidden characters (\n) that where causing the JOLT processor to fail; however like you, it would work via the "Advance Editor". I used escapeJson() on the attribute it works it also makes the \n are visible in the flowfile.

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#escapejson


Simple Example:

[

{

"operation": "default",

"spec": {

"content": "${ext_content:escapeJson()}", <- ext_content attribute contained the issue

"date": "${ext_date}",

"updateDate": "${ext_updateDate}"

}

}

]


Hope this this helps and saves someone else some time!


JF

Don't have an account?
Coming from Hortonworks? Activate your account here