Querying JSON
|
Этот раздел перенесён из документации Camunda 7 и в дальнейшем будет доработан с учётом особенностей OpenBPM Engine |
The JSON datatype supports querying with the JSONPath http://goessner.net/articles/JsonPath/ query language.
Querying an Element
import static io.openbpm.spin.Spin.JSON;
String json = "{\"child\": [{\"id\": 1,\"name\": \"Lucy\",\"sex\": \"female\"},{\"id\": 2,\"name\": \"Tracy\",\"sex\": \"female\"}],\"number\": 1,\"boolean\": true}";
SpinJsonNode child = JSON(json).jsonPath("$.child[0]").element();
Querying an Element List
import static io.openbpm.spin.Spin.JSON;
String json = "{\"child\": [{\"id\": 1,\"name\": \"Lucy\",\"sex\": \"female\"},{\"id\": 2,\"name\": \"Tracy\",\"sex\": \"female\"}],\"number\": 1,\"boolean\": true}";
SpinList<SpinJsonNode> childs = JSON(json).jsonPath("$.child").elementList();
Querying a String
import static io.openbpm.spin.Spin.JSON;
String json = "{\"child\": [{\"id\": 1,\"name\": \"Lucy\",\"sex\": \"female\"},{\"id\": 2,\"name\": \"Tracy\",\"sex\": \"female\"}],\"number\": 1,\"boolean\": true}";
String value = JSON(json).jsonPath("$.child[0].name").stringValue();
Querying a Number
import static io.openbpm.spin.Spin.JSON;
String json = "{\"child\": [{\"id\": 1,\"name\": \"Lucy\",\"sex\": \"female\"},{\"id\": 2,\"name\": \"Tracy\",\"sex\": \"female\"}],\"number\": 1,\"boolean\": true}";
Double count = JSON(json).jsonPath("$.number").numberValue();
Querying a Boolean
import static io.openbpm.spin.Spin.JSON;
String json = "{\"child\": [{\"id\": 1,\"name\": \"Lucy\",\"sex\": \"female\"},{\"id\": 2,\"name\": \"Tracy\",\"sex\": \"female\"}],\"number\": 1,\"boolean\": true}";
Boolean exists = JSON(json).jsonPath("$.boolean").boolValue();
Filtering a Query
Be aware that a filtering expression - the expression in the () - is not allowed to contain double quotes!
import static io.openbpm.spin.Spin.JSON;
String json = "{\"child\": [{\"id\": 1,\"name\": \"Lucy\",\"sex\": \"female\"},{\"id\": 2,\"name\": \"Tracy\",\"sex\": \"female\"}],\"number\": 1,\"boolean\": true}";
SpinList<SpinJsonNode> girls = JSON(json).jsonPath("$.child[?(@.sex == 'female')]").elementList();
Лицензия и атрибуция
Эта документация была создана на базе материала "Camunda 7 Docs" от Camunda, находится под лицензией Creative Commons Attribution-ShareAlike 3.0 Unported License .
Оригинал документации: https://docs.camunda.org