Support Questions

Find answers, ask questions, and share your expertise

JoltTransformation unable to marshal json

avatar
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

avatar
New Contributor

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

avatar
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