{"record":{"id":"db670220981454ff","repo":"pentaho/pentaho-kettle","slug":"jsoninput-error-badstructure","errorCode":"JsonInput.Error.BadStructure","errorMessage":"JsonInput.Error.BadStructure","messagePattern":"JsonInput\\.Error\\.BadStructure","errorType":"exception","errorClass":"JsonInputException","httpStatus":null,"severity":"error","filePath":"plugins/json/core/src/main/java/org/pentaho/di/trans/steps/jsoninput/reader/FastJsonReader.java","lineNumber":245,"sourceCode":"      // built at ctor\n      return true;\n    }\n\n    @Override\n    public void clear() {\n      results.clear();\n    }\n  }\n\n  private List<List<?>> evalCombinedResult() throws JsonInputException {\n    int lastSize = -1;\n    String prevPath = null;\n    List<List<?>> results = new ArrayList<>( compiledJsonPaths.length );\n    int i = 0;\n    for ( JsonPath path : compiledJsonPaths ) {\n      List<Object> result = getReadContext().read( path );\n      if ( result.size() != lastSize && lastSize > 0 && !result.isEmpty() ) {\n        throw new JsonInputException( BaseMessages.getString(\n          PKG, \"JsonInput.Error.BadStructure\", result.size(), inputFields[ i ].getPath(), prevPath, lastSize ) );\n      }\n      if ( !isIgnoreMissingPath() && ( isAllNull( result ) || result.isEmpty() ) ) {\n        throw new JsonInputException(\n          BaseMessages.getString( PKG, \"JsonReader.Error.CanNotFindPath\", inputFields[ i ].getPath() ) );\n      }\n      results.add( result );\n      lastSize = result.size();\n      prevPath = inputFields[ i ].getPath();\n      i++;\n    }\n    return results;\n  }\n\n  public static boolean isAllNull( Iterable<?> list ) {\n    for ( Object obj : list ) {\n      if ( obj != null ) {\n        return false;","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/json/core/src/main/java/org/pentaho/di/trans/steps/jsoninput/reader/FastJsonReader.java#L227-L263","documentation":"JsonInputException with message key JsonInput.Error.BadStructure thrown by FastJsonReader.evalCombinedResult when two JSONPath expressions return result lists of different sizes, meaning the JSON structure is inconsistent with the configured parallel field paths. The message includes the mismatched sizes and the two offending paths.","triggerScenarios":"evalCombinedResult: for JsonPath path i, result.size() != lastSize while lastSize > 0 and result non-empty — i.e. field paths expected to yield parallel arrays (e.g. $.a[*] with 10 matches vs $.b[*] with 7 matches) within one input object.","commonSituations":"Configuring several wildcard paths ($.items[*].name, $.items[*].id) against JSON where one array is shorter or nested differently; schema drift from an API version change; optional arrays missing elements; wrong wildcard depth ($..id vs $.items[*].id).","solutions":["Align all configured field paths so each wildcard path matches the same array: use a common root like $.items[*].name and $.items[*].id.","Inspect the source JSON and confirm all mapped arrays have the same length at the same nesting level.","Enable 'Ignore missing path' only if genuinely optional — it does not fix size mismatches, only missing/null paths.","If the source schema changed, update the paths or normalize the JSON upstream with a transformation.","Add a JSONPath assertion pre-check (e.g. with Jayway JsonPath) to verify equal result sizes before running the step."],"exampleFix":"// before: mismatched paths\n$.items[*].name  (10 results)\n$.details[*].id  (7 results)\n// after: aligned under one array\n$.items[*].name\n$.items[*].id","handlingStrategy":"validation","validationCode":"// pre-check that all mapped JSONPath arrays have equal size\nConfiguration cfg = Configuration.defaultConfiguration();\nDocumentContext ctx = JsonPath.parse(json);\nint size = -1;\nfor (String p : paths) {\n  int n = ctx.read(p, new TypeRef<List<Object>>(){}).size();\n  if (size > 0 && n != size) throw new IllegalStateException(\"Path \" + p + \" size \" + n + \" != \" + size);\n  size = n;\n}","typeGuard":null,"tryCatchPattern":"try { runTransformation(); }\ncatch (KettleException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"BadStructure\")) {\n    // log the two offending paths from the message and realign field config\n  } else throw e;\n}","preventionTips":["Always derive all field paths from one common wildcard root ($.items[*].x, $.items[*].y).","Pin and review API schemas — version drift changes array shapes.","Snapshot a sample response and validate paths with Jayway JsonPath in tests.","Use consistent wildcard depth; avoid mixing $..x recursive descent with indexed paths."],"tags":["json","jsonpath","schema-mismatch","kettle"],"backgroundTag":"unexpected-response-shape","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"}