#1063·JsonPath

regex and nested array

Author: rigazillaCreated Nov 13, 2025Updated Nov 13, 2025

regex filter on an array returns all the matching string and all the nested array with a match.

Is that by design?

Reproducer

///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS com.jayway.jsonpath:json-path:2.9.0

import com.jayway.jsonpath.JsonPath; import java.util.List;

public class RegexArrayFilterExample { public static void main(String[] args) { String json = """ { "data": [ "apple", "banana", ["nested-apple", "nested-banana"], "application" ] } """;

    System.out.println("JSON: " + json);
    // Filter strings matching regex pattern
    List<Object> result = JsonPath.read(json, "$.data[?(@ =~ /.*app.*/)]");
    System.out.println("Result: " + result);
}

}