<?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 Re: Convert JSON Attribute to Number in NiFi workflow in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210777#M71920</link>
    <description>&lt;P&gt;First of all, thank you for the fast reply!&lt;/P&gt;&lt;P&gt;I'm using NiFi version 1.3.0 and the original column in my table is of type Double. I'm reading out the data by a QueryDatabaseTable processor, afterwards calling a ConvertAvroToJson. To split the array into separete objects I'm using a SplitJson processor. So far, everything seems to be good. Each object looks like this:&lt;/P&gt;&lt;PRE&gt;{"ID":null,"Timestamp":"2017-05-17 17:45:55.0","Name":"asdhybridUL2N","Value":225.0}&lt;/PRE&gt;&lt;P&gt;In order to remove the "ID" attribute (is mostly null and not needed later), adding the "tags" attribute (which shall contain the fix values (a=b, c=d) as shown in the question) and changing "Name" attribute to "metric", I use a mix of UpdateAttribute, AttributesToJson and ReplaceText processors. And that's were the type of the value attribute changes to String. I also saw this JoltTransformJSON processor, but to be honest, I'm not the JSON expert and I didn't understand how to use it in my case.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Nov 2017 15:05:41 GMT</pubDate>
    <dc:creator>dmueller1607</dc:creator>
    <dc:date>2017-11-29T15:05:41Z</dc:date>
    <item>
      <title>Convert JSON Attribute to Number in NiFi workflow</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210775#M71918</link>
      <description>&lt;P&gt;I created a NiFi Workflow that reads in data from a Database table into Avro, and later into JSON format. &lt;/P&gt;&lt;P&gt;However, at the moment my JSON object looks the following:&lt;/P&gt;&lt;PRE&gt;{
  "metric" : "asdpacaduPwirkL1",
  "value" : "-495.07000732421875",
  "timestamp" : "2017-05-16 12:57:39.0",
  "tags" : {
    "a" : "b",
    "c" : "d"
  }
}
&lt;/PRE&gt;&lt;P&gt;This is quite good, but as a last step I have to convert to "value" attribute value into a Number (it is a String at the moment), so my final JSON should look like&lt;/P&gt;&lt;PRE&gt;{
  "metric" : "asdpacaduPwirkL1",
  "value" : -495.07000732421875,			// this should be changed into a number
  "timestamp" : "2017-05-16 12:57:39.0",
  "tags" : {
    "a" : "b",
    "c" : "d"
  }
}&lt;/PRE&gt;&lt;P&gt;Which NiFi processor can I use for that and how to convert the data type from String to Number? &lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2017 23:42:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210775#M71918</guid>
      <dc:creator>dmueller1607</dc:creator>
      <dc:date>2017-11-28T23:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Attribute to Number in NiFi workflow</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210776#M71919</link>
      <description>&lt;P&gt;What version of NiFi are you using? Is the "value" column in your database table a String or a Float/Double? What processor(s) are you using to read from the database? If using ExecuteSQL, could you do something like the following?&lt;/P&gt;&lt;PRE&gt;SELECT metric, CAST(value AS DOUBLE) AS value, timestamp, tags from myTable&lt;/PRE&gt;&lt;P&gt;Alternatively, as of NiFi 1.2.0 (HDF 3.0) you can use the &lt;A target="_blank" href="http://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.4.0/org.apache.nifi.processors.standard.JoltTransformJSON/index.html"&gt;JoltTransformJSON&lt;/A&gt; processor to do type conversion (see an example &lt;A target="_blank" href="http://jolt-demo.appspot.com/#modify-typeConversion"&gt;here&lt;/A&gt;). Also if you know what the schema is supposed to be, you could use &lt;A target="_blank" href="http://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.4.0/org.apache.nifi.processors.standard.ConvertRecord/index.html"&gt;ConvertRecord&lt;/A&gt; with a &lt;A target="_blank" href="http://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services-nar/1.4.0/org.apache.nifi.json.JsonRecordSetWriter/index.html"&gt;JsonRecordSetWriter&lt;/A&gt; which is associated with the "correct" schema.  The reader can be an &lt;A target="_blank" href="http://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services-nar/1.4.0/org.apache.nifi.avro.AvroReader/index.html"&gt;AvroReader&lt;/A&gt; which uses the Embedded Schema.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 02:42:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210776#M71919</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-11-29T02:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Attribute to Number in NiFi workflow</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210777#M71920</link>
      <description>&lt;P&gt;First of all, thank you for the fast reply!&lt;/P&gt;&lt;P&gt;I'm using NiFi version 1.3.0 and the original column in my table is of type Double. I'm reading out the data by a QueryDatabaseTable processor, afterwards calling a ConvertAvroToJson. To split the array into separete objects I'm using a SplitJson processor. So far, everything seems to be good. Each object looks like this:&lt;/P&gt;&lt;PRE&gt;{"ID":null,"Timestamp":"2017-05-17 17:45:55.0","Name":"asdhybridUL2N","Value":225.0}&lt;/PRE&gt;&lt;P&gt;In order to remove the "ID" attribute (is mostly null and not needed later), adding the "tags" attribute (which shall contain the fix values (a=b, c=d) as shown in the question) and changing "Name" attribute to "metric", I use a mix of UpdateAttribute, AttributesToJson and ReplaceText processors. And that's were the type of the value attribute changes to String. I also saw this JoltTransformJSON processor, but to be honest, I'm not the JSON expert and I didn't understand how to use it in my case.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 15:05:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210777#M71920</guid>
      <dc:creator>dmueller1607</dc:creator>
      <dc:date>2017-11-29T15:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Attribute to Number in NiFi workflow</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210778#M71921</link>
      <description>&lt;P&gt;Yeah the JOLT DSL can be confusing at times. Here's a Chain Spec that does what you describe above, so you can replace your processors with JoltTransformJSON: &lt;/P&gt;&lt;PRE&gt;[
  {
    "operation": "shift",
    "spec": {
      "Name": "metric",
      "Timestamp": "&amp;amp;"
    }
  },
  {
    "operation": "default",
    "spec": {
      "tags": {
        "c": "d",
        "a": "b"
      }
    }
  }
]&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Nov 2017 02:20:11 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210778#M71921</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-11-30T02:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Attribute to Number in NiFi workflow</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210779#M71922</link>
      <description>&lt;P&gt;If I have this template now, I'll try to change my workflow. Thank you very much for this easy-looking solution!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Nov 2017 15:17:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/210779#M71922</guid>
      <dc:creator>dmueller1607</dc:creator>
      <dc:date>2017-11-30T15:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert JSON Attribute to Number in NiFi workflow</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/289512#M71923</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/38301"&gt;@mburgess&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have an input string but don't know what the value might be, e.g. it could be "8" or "8.4", and want to convert this into an int. Is there a way you can convert the "8" to an 8 and the "8.4" to an 8.4 float?&lt;/P&gt;&lt;P&gt;Currently I am only able to convert both to ints as 8, or both to floats as 8.0, and 8.4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For context, I am using a ValidateRecord to validate the number is an int, so would not like float values to be validated. This means that if an input is converted from a string into a number, I would like to know whether it is a decimal or integer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you able to please assist?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 12:07:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Convert-JSON-Attribute-to-Number-in-NiFi-workflow/m-p/289512#M71923</guid>
      <dc:creator>wblake</dc:creator>
      <dc:date>2020-02-11T12:07:36Z</dc:date>
    </item>
  </channel>
</rss>

