<?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 Avro Schema for Array of Json Object in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Avro-Schema-for-Array-of-Json-Object/m-p/190442#M73568</link>
    <description>&lt;P&gt;
	Hello,&lt;/P&gt;&lt;P&gt;
	I'm trying to convert an array of Json to avro and I'm facing some difficulties. This is the Json I want to convert:&lt;/P&gt;&lt;PRE&gt;[{"MeasureId":"nifiHeartBeat", "Value":"1", "AuditDateTime":"Tue Jan 16 13:48:58 CET 2018", "DATA_SOURCE":"20083"}]&lt;/PRE&gt;&lt;P&gt;And here is the schema I'm declaring in the ConvertJSONToAvro processor (based on what I rode &lt;A target="_blank" href="https://community.hortonworks.com/questions/149593/jsonrecordsetwriter-not-reading-avro-schema-as-exp.html"&gt;here&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;{
    "type": "record",
    "name": "NifiHeartBeat_v3",
    "fields": [
       {
            "name": "columns",
            "type": {
                "type": "array",
                "items": {
                    "type": "record",
                    "name": "columnValues",
                    "fields": [
                        {
                            "name": "MeasureId",
                            "type": "string",
                            "default": "null"
                        },
                        {
                            "name": "Value",
                            "type": "string",
                            "default": "null"
                        },
                        {
                            "name": "AuditDateTime",
                            "type": "string",
                            "default": "null"
                        },
                        {
                            "name": "DATA_SOURCE",
                            "type": "string",
                            "default": "null"
                        }
                    ]
                }
            }
        }
    ]
}
&lt;/PRE&gt;&lt;P&gt;This is the error I'm getting:&lt;/P&gt;&lt;PRE&gt;2018-01-16 14:00:25,780 WARN [Timer-Driven Process Thread-3] o.a.n.processors.kite.ConvertJSONToAvro ConvertJSONToAvro[id=b0a67367-f541-38d5-176f-c07d4a75dd24] Failed to convert 1/1 records from JSON to Avro&lt;/PRE&gt;&lt;P&gt;Note: If I get this to work I would move the schema to Hortonworks Schema-Registry, but I wanted to get it work in "local" first.&lt;/P&gt;&lt;P&gt;Could someone help me please?&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jan 2018 21:05:51 GMT</pubDate>
    <dc:creator>j_rodriguez</dc:creator>
    <dc:date>2018-01-16T21:05:51Z</dc:date>
    <item>
      <title>Avro Schema for Array of Json Object</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Avro-Schema-for-Array-of-Json-Object/m-p/190442#M73568</link>
      <description>&lt;P&gt;
	Hello,&lt;/P&gt;&lt;P&gt;
	I'm trying to convert an array of Json to avro and I'm facing some difficulties. This is the Json I want to convert:&lt;/P&gt;&lt;PRE&gt;[{"MeasureId":"nifiHeartBeat", "Value":"1", "AuditDateTime":"Tue Jan 16 13:48:58 CET 2018", "DATA_SOURCE":"20083"}]&lt;/PRE&gt;&lt;P&gt;And here is the schema I'm declaring in the ConvertJSONToAvro processor (based on what I rode &lt;A target="_blank" href="https://community.hortonworks.com/questions/149593/jsonrecordsetwriter-not-reading-avro-schema-as-exp.html"&gt;here&lt;/A&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;{
    "type": "record",
    "name": "NifiHeartBeat_v3",
    "fields": [
       {
            "name": "columns",
            "type": {
                "type": "array",
                "items": {
                    "type": "record",
                    "name": "columnValues",
                    "fields": [
                        {
                            "name": "MeasureId",
                            "type": "string",
                            "default": "null"
                        },
                        {
                            "name": "Value",
                            "type": "string",
                            "default": "null"
                        },
                        {
                            "name": "AuditDateTime",
                            "type": "string",
                            "default": "null"
                        },
                        {
                            "name": "DATA_SOURCE",
                            "type": "string",
                            "default": "null"
                        }
                    ]
                }
            }
        }
    ]
}
&lt;/PRE&gt;&lt;P&gt;This is the error I'm getting:&lt;/P&gt;&lt;PRE&gt;2018-01-16 14:00:25,780 WARN [Timer-Driven Process Thread-3] o.a.n.processors.kite.ConvertJSONToAvro ConvertJSONToAvro[id=b0a67367-f541-38d5-176f-c07d4a75dd24] Failed to convert 1/1 records from JSON to Avro&lt;/PRE&gt;&lt;P&gt;Note: If I get this to work I would move the schema to Hortonworks Schema-Registry, but I wanted to get it work in "local" first.&lt;/P&gt;&lt;P&gt;Could someone help me please?&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 21:05:51 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Avro-Schema-for-Array-of-Json-Object/m-p/190442#M73568</guid>
      <dc:creator>j_rodriguez</dc:creator>
      <dc:date>2018-01-16T21:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Avro Schema for Array of Json Object</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Avro-Schema-for-Array-of-Json-Object/m-p/190443#M73569</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/18856/jrodriguez.html" nodeid="18856" target="_blank"&gt;@JAROB&lt;/A&gt;&lt;P&gt;Try with the below Record Schema property&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;ConvertJSONToAvro Configs:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Record schema
&lt;/P&gt;&lt;PRE&gt;{ "type": "record", "name": "NifiHeartBeat_v3", "fields": [{ "name": "MeasureId", "type": "string", "default": "null" }, { "name": "Value", "type": "string", "default": "null" }, { "name": "AuditDateTime", "type": "string", "default": "null" }, { "name": "DATA_SOURCE", "type": "string", "default": "null" }] }&lt;/PRE&gt;&lt;P&gt;And &lt;STRONG&gt;if you are testing with one json message&lt;/STRONG&gt; then don’t enclose the &lt;STRONG&gt;whole json message in [](square brackets)&lt;/STRONG&gt; because when we enclose the message in [] convertjsontoavro won’t parse the array message, we need to split the array if array having one message in it.&lt;/P&gt;&lt;P&gt;Try with json message&lt;/P&gt;&lt;PRE&gt;{
 "MeasureId": "nifiHeartBeat",
 "Value": "1",
 "AuditDateTime": "Tue Jan 16 13:48:58 CET 2018",
 "DATA_SOURCE": "20083"
}&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;ConvertJSONToAvro configs:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="50424-convertjsontoavro-config.png" style="width: 775px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/18500i13E17422ED617817/image-size/medium?v=v2&amp;amp;px=400" role="button" title="50424-convertjsontoavro-config.png" alt="50424-convertjsontoavro-config.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(or) &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If you need to enclose message with&lt;STRONG&gt; [] &lt;/STRONG&gt;then use split json
processor to split the message&lt;/P&gt;&lt;PRE&gt;[{  "MeasureId":
"nifiHeartBeat",  "Value":
"1",  "AuditDateTime":
"Tue Jan 16 13:48:58 CET 2018",  "DATA_SOURCE":
"20083"}]&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;SplitJson Configs:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Because ConvertJSONtoAVRO processor won't parse array of json messages so we need to split them individually(even array having one message in it) and send to the processor.&lt;/P&gt;&lt;P&gt;1.Add the property value as&lt;/P&gt;&lt;P&gt;JsonPath Expression
&lt;/P&gt;&lt;PRE&gt;$.*&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Configs:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="50425-splitjson.png" style="width: 618px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/18501iBACD3E7CB3B4D69F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="50425-splitjson.png" alt="50425-splitjson.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;ConvertJSONToAvro configs:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Same configs as mentioned above.&lt;/P&gt;&lt;P&gt;If you are using &lt;STRONG&gt;ConvertRecord processor&lt;/STRONG&gt; then we don’t need
to use SplitJSON processor as convert record processor works with array of json
messages.&lt;/P&gt;&lt;P&gt;In addition for your reference i have attached nifi flow templates using convertjsontoavro processor and using convertrecord processor to convert json message to avro, so that you can save and reuse the templates.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/50426-json-to-avro-using-convertrecord.xml" target="_blank"&gt;json-to-avro-using-convertrecord.xml&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/50426-json-to-avro-using-convertrecord.xml" target="_blank"&gt;&lt;/A&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/50427-json-to-avro-conversion-using-convertjsontoavro-pr.xml" target="_blank"&gt;json-to-avro-conversion-using-convertjsontoavro-pr.xml&lt;/A&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;If the Answer helped to resolve your issue, &lt;STRONG&gt;Click on Accept button below to accept the answer&lt;/STRONG&gt;, That would be great help to Community users to find solution quickly for these kind of errors.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2019 07:36:11 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Avro-Schema-for-Array-of-Json-Object/m-p/190443#M73569</guid>
      <dc:creator>Shu_ashu</dc:creator>
      <dc:date>2019-08-18T07:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Avro Schema for Array of Json Object</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Avro-Schema-for-Array-of-Json-Object/m-p/190444#M73570</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/18929/yaswanthmuppireddy.html" nodeid="18929"&gt;@Shu&lt;/A&gt; &lt;/P&gt;&lt;P&gt;Thank you so much for your answer and for taking time to prepare an environment to test my PoC. I really appreciate that. My problem was that I was trying to read the Json with "JsonPathReader" service. Changing to "JsonTreeReader" made the trick.&lt;/P&gt;&lt;P&gt;Anyway, I went forward with the PoC and now I'm sending the converted Avro data to a Kafka cluster and I'm trying to deserialize it after consuming. For all this, I'm using the Hortonworks schema-registry which works fine in Nifi but I can't get it to work in Java. I've tryied the example &lt;A href="https://github.com/hortonworks/registry/blob/HDF-2.1.0.0/examples/schema-registry/avro/src/main/java/com/hortonworks/registries/schemaregistry/examples/avro/SampleSchemaRegistryClientApp.java"&gt;here&lt;/A&gt; but I'm getting an error at the time of declaring the deserializedObject.&lt;/P&gt;&lt;P&gt;Here you can see the code:&lt;/P&gt;&lt;PRE&gt;    public void runAvroSerDesApis(byte[] serializedData, String name) throws IOException {
        this.serializedData = serializedData;
        this.name = name;
        //using builtin avro serializer/deserializer
        /*AvroSnapshotSerializer avroSnapshotSerializer = new AvroSnapshotSerializer();
        avroSnapshotSerializer.init(config);*/
        AvroSnapshotDeserializer deserializer = schemaRegistryClient.getDefaultDeserializer(AvroSchemaProvider.TYPE);
        deserializer.init(config);


        Object deviceObject = createGenericRecordForDevice(name);


        SchemaMetadata schemaMetadata = createSchemaMetadata("avro-serializer-schema-" + System.currentTimeMillis());
        //byte[] serializedData = avroSnapshotSerializer.serialize(deviceObject, schemaMetadata);
        Object deserializedObj = deserializer.deserialize(new ByteArrayInputStream(serializedData), schemaMetadata, null);


        LOG.info("Serialized and deserialized objects are equal: [{}] ", deviceObject.equals(deserializedObj));
    }
&lt;/PRE&gt;&lt;P&gt;The line retrieving the error is "Object deserializedObj = deserializer.deserialize(new ByteArrayInputStream(serializedData), schemaMetadata, null);" and it says more or less that &lt;EM&gt;"actual and format argument lists differ in lenght"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Is there any example someone could provide about how to deserialize an Avro message in Java using Hortonworks Schema-Registry? I'm using v0.2.1.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 16:29:48 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Avro-Schema-for-Array-of-Json-Object/m-p/190444#M73570</guid>
      <dc:creator>j_rodriguez</dc:creator>
      <dc:date>2018-01-19T16:29:48Z</dc:date>
    </item>
  </channel>
</rss>

