hibernate/hibernate-orm · error · QueryException

JSON path does not end with an array index: ${jsonPath}

Error message

JSON path does not end with an array index: ${jsonPath}

What it means

Error "JSON path does not end with an array index: ${jsonPath}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/json/SQLServerJsonArrayInsertFunction.java:38

public class SQLServerJsonArrayInsertFunction extends AbstractJsonArrayInsertFunction {

	public SQLServerJsonArrayInsertFunction(TypeConfiguration typeConfiguration) {
		super( typeConfiguration );
	}

	@Override
	public void render(
			SqlAppender sqlAppender,
			List<? extends SqlAstNode> arguments,
			ReturnableType<?> returnType,
			SqlAstTranslator<?> translator) {
		final String jsonPath = translator.<String>getLiteralValue( (Expression) arguments.get( 1 ) ).trim();
		final int bracketEndIndex = jsonPath.lastIndexOf( ']' );
		final int bracketStartIndex = jsonPath.lastIndexOf( '[' );
		if ( jsonPath.isEmpty()
				|| bracketEndIndex != jsonPath.length() - 1
				|| bracketStartIndex == -1 ) {
			throw new QueryException( "JSON path does not end with an array index: " + jsonPath );
		}
		final int index;
		try {
			index = Integer.parseInt( jsonPath.substring( bracketStartIndex + 1, bracketEndIndex ) );
		}
		catch ( NumberFormatException e ) {
			throw new QueryException( "JSON path does not point to a valid array index: " + jsonPath );
		}
		final Expression json = (Expression) arguments.get( 0 );
		final SqlAstNode value = arguments.get( 2 );
		// Only replace data if this is an array
		sqlAppender.appendSql( "(select case when left(json_query(x.d,x.p),1)='[' then " );
		// Replace the array
		sqlAppender.appendSql( "json_modify(x.d,x.p,json_query((" );
		// Aggregate a new JSON array based on element rows
		sqlAppender.appendSql( "select '['+string_agg(t.v,',') within group (order by t.k)+']' from (" );

		sqlAppender.appendSql( "select x.i k,x.v v union all " );

View on GitHub (pinned to fad1729dce)

Solutions

  1. End the JSON path with an array index, e.g. '$.a[0]'.

When it happens

Trigger: Triggered when the application calls a Hibernate dialect feature that the configured database dialect cannot provide: JSON path does not end with an array index (SQL Server).

Common situations: 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 end with an array index (SQL Server).


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/1f914aca674458b1. Report an issue: GitHub.