<?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: [NiFi 1.23.2] Validating JSON, against a schema present as a flow file attribute in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/NiFi-1-23-2-Validating-JSON-against-a-schema-present-as-a/m-p/412835#M253714</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/121295"&gt;@phadkev&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Have you considered using the &lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.28.0/org.apache.nifi.processors.standard.ValidateRecord/index.html" target="_blank"&gt;ValidateRecord&lt;/A&gt; processor instead of the ValidateJson?&lt;BR /&gt;&lt;BR /&gt;The ValidateRecord processor can be configured with a JSON reader.&amp;nbsp; The Json readers can be configured to use "Schema Text".&amp;nbsp; The Schema text property support expression language allowing you to extract the Schema you want to use from an inbound FlowFile attribute.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Please help our community grow. If you found&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;any&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "&lt;SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Accept as Solution&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;" on&amp;nbsp;&lt;STRONG&gt;one or more&lt;/STRONG&gt;&amp;nbsp;of them that helped.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you,&lt;BR /&gt;Matt&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Nov 2025 17:19:35 GMT</pubDate>
    <dc:creator>MattWho</dc:creator>
    <dc:date>2025-11-06T17:19:35Z</dc:date>
    <item>
      <title>[NiFi 1.23.2] Validating JSON, against a schema present as a flow file attribute</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-1-23-2-Validating-JSON-against-a-schema-present-as-a/m-p/412832#M253711</link>
      <description>&lt;P&gt;I want to validate my JSON objects against an schema like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "type": "object",
    "required": [
        "apple",
        "banana",
        "orange"
    ],
    "properties": {
        "apple": {
            "type": "object",
            "required": [
                "header",
                "enableAlert"
            ],
            "properties": {
                "header": {
                    "type": "string"
                },
                "enableAlert": {
                    "type": [
                        "boolean",
                        "string"
                    ],
                    "enum": [
                        true,
                        false,
                        "true",
                        "false"
                    ]
                }
            },
            "additionalProperties": true
        },
        "orange": {
            "type": "object",
            "required": [
                "test1",
                "test2"
            ],
            "properties": {
                "test1": {
                    "type": "string"
                },
                "test2": {
                    "type": "string"
                }
            }
        },
        "banana": {
            "type": "boolean"
        },
        "additionalProperties": true
    }
}&lt;/LI-CODE&gt;&lt;P&gt;The schema can change per flow file, so I want to derive it from flow file attribute and then use it as ${schema}. In the ValidateJSON 1.23.2 processor, the schema can't be derived from EL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="phadkev_0-1762430775281.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/46428i863374133A244BB9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="phadkev_0-1762430775281.png" alt="phadkev_0-1762430775281.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;So I thought of using a script like this:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;import org.apache.nifi.processor.io.StreamCallback
import java.nio.charset.StandardCharsets
import org.json.JSONObject
import org.everit.json.schema.loader.SchemaLoader
import org.everit.json.schema.ValidationException
import org.everit.json.schema.Schema

def flowFile = session.get()
if (!flowFile) return

def schemaStr = flowFile.getAttribute('schema')
if (!schemaStr) {
    log.error("No 'schema' attribute found.")
    session.transfer(flowFile, REL_FAILURE)
    return
}

def isValid = true
def errorMsg = ""

flowFile = session.write(flowFile, { inputStream, outputStream -&amp;gt;
    def content = new String(inputStream.bytes, StandardCharsets.UTF_8)
    try {
        def jsonData = new JSONObject(content)
        def jsonSchema = new JSONObject(schemaStr)
        def schema = SchemaLoader.load(jsonSchema)
        schema.validate(jsonData)
    } catch (ValidationException e) {
        isValid = false
        errorMsg = e.allMessages.join("; ")
    } catch (Exception e) {
        isValid = false
        errorMsg = e.message
    }
    outputStream.write(content.bytes)
} as StreamCallback)

if (isValid) {
    log.info("JSON validated successfully.")
    session.transfer(flowFile, REL_SUCCESS)
} else {
    log.error("JSON validation failed: ${errorMsg}")
    flowFile = session.putAttribute(flowFile, 'validation.error', errorMsg)
    session.transfer(flowFile, REL_FAILURE)
}&lt;/LI-CODE&gt;&lt;P class="lia-align-justify"&gt;This is my setup:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="phadkev_1-1762430899141.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/46429i50B8D0AE6F279165/image-size/medium?v=v2&amp;amp;px=400" role="button" title="phadkev_1-1762430899141.png" alt="phadkev_1-1762430899141.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ls /root/integration_src/workarea/nifi/scripts/lib
json-20231013.jar  org.everit.json.schema-1.14.3.jar&lt;/LI-CODE&gt;&lt;P class="lia-align-justify"&gt;I am getting this error now:&lt;/P&gt;&lt;PRE&gt;ExecuteScript[id=58d580dd-019a-1000-4e36-7b54d5c2d161] Processing failed: org.apache.nifi.processor.exception.ProcessException: javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script5.groovy: 15: unable to resolve class org.everit.json.schema.loader.SchemaLoader
 @ line 15, column 1.
   import org.everit.json.schema.loader.SchemaLoader
   ^

Script5.groovy: 16: unable to resolve class org.everit.json.schema.ValidationException
 @ line 16, column 1.
   import org.everit.json.schema.ValidationException
   ^

Script5.groovy: 17: unable to resolve class org.everit.json.schema.Schema
 @ line 17, column 1.
   import org.everit.json.schema.Schema
   ^

3 errors&lt;/PRE&gt;&lt;P class="lia-align-justify"&gt;Any idea on how to resolve the error?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Nov 2025 12:11:05 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-1-23-2-Validating-JSON-against-a-schema-present-as-a/m-p/412832#M253711</guid>
      <dc:creator>phadkev</dc:creator>
      <dc:date>2025-11-06T12:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: [NiFi 1.23.2] Validating JSON, against a schema present as a flow file attribute</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NiFi-1-23-2-Validating-JSON-against-a-schema-present-as-a/m-p/412835#M253714</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/121295"&gt;@phadkev&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Have you considered using the &lt;A href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.28.0/org.apache.nifi.processors.standard.ValidateRecord/index.html" target="_blank"&gt;ValidateRecord&lt;/A&gt; processor instead of the ValidateJson?&lt;BR /&gt;&lt;BR /&gt;The ValidateRecord processor can be configured with a JSON reader.&amp;nbsp; The Json readers can be configured to use "Schema Text".&amp;nbsp; The Schema text property support expression language allowing you to extract the Schema you want to use from an inbound FlowFile attribute.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Please help our community grow. If you found&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;any&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "&lt;SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Accept as Solution&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;" on&amp;nbsp;&lt;STRONG&gt;one or more&lt;/STRONG&gt;&amp;nbsp;of them that helped.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you,&lt;BR /&gt;Matt&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Nov 2025 17:19:35 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NiFi-1-23-2-Validating-JSON-against-a-schema-present-as-a/m-p/412835#M253714</guid>
      <dc:creator>MattWho</dc:creator>
      <dc:date>2025-11-06T17:19:35Z</dc:date>
    </item>
  </channel>
</rss>

