Skip to content

Instantly share code, notes, and snippets.

@robinhowlett
Created June 4, 2021 17:12
Show Gist options
  • Save robinhowlett/9b405d72162ba75ecc856b87298ea5f2 to your computer and use it in GitHub Desktop.
Save robinhowlett/9b405d72162ba75ecc856b87298ea5f2 to your computer and use it in GitHub Desktop.
JBang.dev-compatible test for Jayway Json negative filters for empty strings
//DEPS com.jayway.jsonpath:json-path:2.1.0
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.ReadContext;
import java.util.List;
public class JsonPathTest {
public static void main(String[] args) {
String json = "{\"phoneNumbers\": [\"a\", 1, false, \"\", null, \"hi\", -1]}";
ReadContext ctx = JsonPath.parse(json);
List<Object> result = ctx.read("$.phoneNumbers[?(@ != '')]");
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment