<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question NiFi - How to extract key value from a string  to JSON in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/NiFi-How-to-extract-key-value-from-a-string-to-JSON/m-p/355425#M237094</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to NiIf and need your help please.&lt;BR /&gt;I have a HandleHttpRequest processor and want to get the URL parameters into JSON.&lt;BR /&gt;&lt;BR /&gt;The URL looks similar to this:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://mydomain.de/getsomedata?key1=value1&amp;amp;key2=value2" target="_blank" rel="noopener"&gt;http://mydomain.de/getsomedata?key1=value1&amp;amp;key2=value2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but may can also be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://mydomain.de/getsomedata?key1=value1&amp;amp;key2=value2" target="_blank" rel="noopener"&gt;http://mydomain.de/getsomedata?myVar1=myValue1&amp;amp;myVar2=value2&amp;amp;lang=DE&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;So No. of parameter and parameter names and values can change of course.&lt;BR /&gt;Now I need a processor that extracts any of key/value pairs from http.query.string into:&lt;BR /&gt;&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; params: {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; "key1":"value1",&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; "key2":"value2"&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or for 2nd example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; params: {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; "myVar1":"value1",&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; "myVar2":"value2",&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; "lang":"DE"&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve that? Is there any processor I can use or should I use ExecuteScript processor?&lt;/P&gt;</description>
    <pubDate>Wed, 19 Oct 2022 14:04:44 GMT</pubDate>
    <dc:creator>MrBurns</dc:creator>
    <dc:date>2022-10-19T14:04:44Z</dc:date>
    <item>
      <title>NiFi - How to extract key value from a string  to JSON</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-How-to-extract-key-value-from-a-string-to-JSON/m-p/355425#M237094</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to NiIf and need your help please.&lt;BR /&gt;I have a HandleHttpRequest processor and want to get the URL parameters into JSON.&lt;BR /&gt;&lt;BR /&gt;The URL looks similar to this:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://mydomain.de/getsomedata?key1=value1&amp;amp;key2=value2" target="_blank" rel="noopener"&gt;http://mydomain.de/getsomedata?key1=value1&amp;amp;key2=value2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but may can also be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://mydomain.de/getsomedata?key1=value1&amp;amp;key2=value2" target="_blank" rel="noopener"&gt;http://mydomain.de/getsomedata?myVar1=myValue1&amp;amp;myVar2=value2&amp;amp;lang=DE&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;So No. of parameter and parameter names and values can change of course.&lt;BR /&gt;Now I need a processor that extracts any of key/value pairs from http.query.string into:&lt;BR /&gt;&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; params: {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; "key1":"value1",&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; "key2":"value2"&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or for 2nd example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; params: {&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; "myVar1":"value1",&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; "myVar2":"value2",&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; "lang":"DE"&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve that? Is there any processor I can use or should I use ExecuteScript processor?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 14:04:44 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-How-to-extract-key-value-from-a-string-to-JSON/m-p/355425#M237094</guid>
      <dc:creator>MrBurns</dc:creator>
      <dc:date>2022-10-19T14:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: NiFi - How to extract key value from a string  to JSON</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-How-to-extract-key-value-from-a-string-to-JSON/m-p/355991#M237175</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/101265"&gt;@MrBurns&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;You want to take the URL that written to the FlowFile's attribute "&lt;SPAN&gt;http.request.uri" and generate a Json, correct?&lt;BR /&gt;&lt;/SPAN&gt;Where do you want to write that JSON (a new FlowFile attribute?&amp;nbsp; Content of the FlowFile?)?&lt;BR /&gt;&lt;BR /&gt;There are multiple ways to handle this.&lt;BR /&gt;If you just want to write JSON to a new FlowFile Attribute, you could use the "Advanced" UI of the UpdateAttribute by setting up a rule for each url type.&lt;BR /&gt;&lt;BR /&gt;If you want to write to the content of a FlowFile, you could follow the above UpdateAttribute with a replaceText processor that does an "always replace" to write the json from the attribute to the content of the FlowFile.&lt;BR /&gt;&lt;BR /&gt;another option here is to use a RouteOnAttribute to route each url type to a unique ReplaceText to handle the specific url type.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I like first option since you can easily add new rules to the UpdateAttribute if any additional URL types are introduced without needing to modify the rest of your dataflow.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="batang,apple gothic"&gt;If you found that the provided solution(s) assisted you with your query, please take a moment to login and click&lt;/FONT&gt;&amp;nbsp;&lt;FONT face="arial black,avant garde" color="#FF0000"&gt;Accept as Solution&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="batang,apple gothic" color="#000000"&gt;below each response that helped.&lt;BR /&gt;&lt;BR /&gt;Thank you,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="batang,apple gothic" color="#000000"&gt;Matt&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 15:59:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-How-to-extract-key-value-from-a-string-to-JSON/m-p/355991#M237175</guid>
      <dc:creator>MattWho</dc:creator>
      <dc:date>2022-10-24T15:59:09Z</dc:date>
    </item>
  </channel>
</rss>

