{"record":{"id":"ed95925f4818c1d6","repo":"hibernate/hibernate-orm","slug":"json-path-does-not-point-to-a-valid-array-index","errorCode":null,"errorMessage":"JSON path does not point to a valid array index: ${jsonPath}","messagePattern":"JSON path does not point to a valid array index: (.+?)","errorType":"exception","errorClass":"QueryException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/function/json/SQLServerJsonArrayInsertFunction.java","lineNumber":45,"sourceCode":"\tpublic void render(\n\t\t\tSqlAppender sqlAppender,\n\t\t\tList<? extends SqlAstNode> arguments,\n\t\t\tReturnableType<?> returnType,\n\t\t\tSqlAstTranslator<?> translator) {\n\t\tfinal String jsonPath = translator.<String>getLiteralValue( (Expression) arguments.get( 1 ) ).trim();\n\t\tfinal int bracketEndIndex = jsonPath.lastIndexOf( ']' );\n\t\tfinal int bracketStartIndex = jsonPath.lastIndexOf( '[' );\n\t\tif ( jsonPath.isEmpty()\n\t\t\t\t|| bracketEndIndex != jsonPath.length() - 1\n\t\t\t\t|| bracketStartIndex == -1 ) {\n\t\t\tthrow new QueryException( \"JSON path does not end with an array index: \" + jsonPath );\n\t\t}\n\t\tfinal int index;\n\t\ttry {\n\t\t\tindex = Integer.parseInt( jsonPath.substring( bracketStartIndex + 1, bracketEndIndex ) );\n\t\t}\n\t\tcatch ( NumberFormatException e ) {\n\t\t\tthrow new QueryException( \"JSON path does not point to a valid array index: \" + jsonPath );\n\t\t}\n\t\tfinal Expression json = (Expression) arguments.get( 0 );\n\t\tfinal SqlAstNode value = arguments.get( 2 );\n\t\t// Only replace data if this is an array\n\t\tsqlAppender.appendSql( \"(select case when left(json_query(x.d,x.p),1)='[' then \" );\n\t\t// Replace the array\n\t\tsqlAppender.appendSql( \"json_modify(x.d,x.p,json_query((\" );\n\t\t// Aggregate a new JSON array based on element rows\n\t\tsqlAppender.appendSql( \"select '['+string_agg(t.v,',') within group (order by t.k)+']' from (\" );\n\n\t\tsqlAppender.appendSql( \"select x.i k,x.v v union all \" );\n\t\tsqlAppender.appendSql( \"select case when cast(t.[key] as int)>=x.i then cast(t.[key] as int)+1 \" );\n\t\tsqlAppender.appendSql( \"else cast(t.[key] as int) end,\" );\n\t\t// type 0 is a null literal\n\t\tsqlAppender.appendSql( \"case t.type when 0 then 'null' when 1 then \");\n\t\t// type 1 is a string literal. to quote it, we use for json path and trim the string down to just the value\n\t\tsqlAppender.appendSql(\n\t\t\t\t\"(select substring(a.v,6,len(a.v)-6) from (select t.value a for json path,without_array_wrapper) a(v))\" );","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/function/json/SQLServerJsonArrayInsertFunction.java#L27-L63","documentation":"Error \"JSON path does not point to a valid array index: ${jsonPath}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Triggered when the application calls a Hibernate dialect feature that the configured database dialect cannot provide: JSON path does not point to a valid array index (SQL Server).","commonSituations":"Common when running against a database whose dialect lacks this capability, when a mapping or HQL/Criteria query requests unsupported functionality, or when the wrong dialect is configured for the database in use. Error: JSON path does not point to a valid array index (SQL Server).","solutions":["Use a valid numeric array index within bounds."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}