How to use jsonpath in GSON How to use jsonpath in GSON json json

How to use jsonpath in GSON


You may use the code below..

public static String getJsonStringForPath(String strJson, String strJPath)    {        Configuration JACKSON_JSON_NODE_CONFIGURATION = Configuration.builder().jsonProvider(new GsonJsonProvider())                .options(Option.ALWAYS_RETURN_LIST, Option.SUPPRESS_EXCEPTIONS).build();        Configuration conf = Configuration.builder().jsonProvider(new GsonJsonProvider())                .options(Option.ALWAYS_RETURN_LIST, Option.SUPPRESS_EXCEPTIONS).build();        JsonArray objArrJ = JsonPath.using(conf).parse(strJson).read(strJPath);             String strRetJson = ""+objArrJ;        return strRetJson;    }//Pass the param of  JsonPath : "$.environment[*].red"

Refer to documentation: of jsonpath : https://github.com/json-path/JsonPath