Skip to content

regex and nested array #1063

@rigazilla

Description

@rigazilla

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);
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions