{"record":{"id":"fd9dfeeee77d80ff","repo":"pentaho/pentaho-kettle","slug":"avroinput-error-jsondecodererror","errorCode":null,"errorMessage":"AvroInput.Error.JsonDecoderError","messagePattern":"AvroInput\\.Error\\.JsonDecoderError","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/avro-format/core/src/main/java/org/pentaho/di/trans/steps/avro/input/AvroNestedReader.java","lineNumber":1489,"sourceCode":"            // just resize the existing incoming array (if necessary) and return\n            // the incoming values\n            result[ 0 ] = RowDataUtil.resizeArray( incoming, m_outputRowMeta.size() );\n            return result;\n          }\n\n          // if necessary, set the current datum reader and top level structure\n          // for the incoming schema\n          if ( m_schemaInField ) {\n            ValueMetaInterface schemaMeta = m_incomingRowMeta.getValueMeta( m_schemaFieldIndex );\n            String schemaToUse = schemaMeta.getString( incoming[ m_schemaFieldIndex ] );\n            setSchemaToUse( schemaToUse, m_cacheSchemas, space );\n          }\n          if ( m_jsonEncoded ) {\n            try {\n              String fieldValue = fieldMeta.getString( incoming[ m_fieldToDecodeIndex ] );\n              m_decoder = m_factory.jsonDecoder( m_schemaToUse, fieldValue );\n            } catch ( IOException e ) {\n              throw new KettleException(\n                BaseMessages.getString( PKG,\n                  \"AvroInput.Error.JsonDecoderError\" ) );\n            }\n          } else {\n            byte[] fieldValue = fieldMeta.getBinary( incoming[ m_fieldToDecodeIndex ] );\n            m_decoder = m_factory.binaryDecoder( fieldValue, null );\n          }\n        }\n\n        if ( m_topLevelRecord != null ) {\n          // special case for top-level record. In case we actually\n          // have a top level union, reassign the record so that\n          // we have the correctly populated object in the case\n          // where our last record instance can't be reused (i.e.\n          // the next record read is a different one from the union\n          // than the last one).\n\n          m_topLevelRecord = (GenericData.Record) m_datumReader.read( m_topLevelRecord, m_decoder );","sourceCodeStart":1471,"sourceCodeEnd":1507,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/avro-format/core/src/main/java/org/pentaho/di/trans/steps/avro/input/AvroNestedReader.java#L1471-L1507","documentation":"When the Avro Input step is configured to decode Avro from a JSON-encoded incoming field, DecoderFactory.jsonDecoder(schema, fieldValue) threw an IOException. AvroNestedReader wraps this in a KettleException, meaning the field's string content is not valid JSON matching the configured schema.","triggerScenarios":"m_jsonEncoded is true and the string read from incoming[m_fieldToDecodeIndex] cannot be decoded as Avro JSON against m_schemaToUse — malformed JSON, wrong encoding, or JSON shape not matching the schema.","commonSituations":"Upstream sends truncated or escaped JSON; field contains plain text/binary instead of JSON; schema configured in the step differs from what the JSON payload represents (missing required fields, wrong types).","solutions":["Log/inspect the raw field value for the failing row to confirm it is valid, complete JSON.","Verify the Avro schema configured in the step matches the JSON payload structure.","Check the 'field to decode' index/selection points at the correct incoming column.","If the data is actually binary Avro, switch the step from JSON to binary decoding mode."],"exampleFix":"// before: field contains malformed/partial JSON\nString fieldValue = fieldMeta.getString(incoming[m_fieldToDecodeIndex]);\n// after: guard upstream\nif (fieldValue == null || !fieldValue.trim().startsWith(\"{\")) throw new KettleException(\"not valid avro-json: \" + fieldValue);","handlingStrategy":"validation","validationCode":"String json = fieldMeta.getString(row[fieldIndex]);\ntry { new org.json.JSONTokener(json).nextValue(); } catch (Exception e) {\n  throw new IllegalArgumentException(\"field is not valid JSON\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  rows = reader.avroObjectToKettle(row, space);\n} catch (KettleException e) {\n  if (e.getMessage().contains(\"JsonDecoderError\")) { logRawValue(row[fieldIndex]); routeToErrorStream(row, e); } else throw e;\n}","preventionTips":["Confirm the decode mode (JSON vs binary) matches the payload format.","Verify the configured schema matches the JSON payload structure.","Log a sample payload when configuring the step."],"tags":["avro","json","decoder","parsing"],"backgroundTag":"json-decode-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}