jsonpath

Getting parent of matched element with jsonpath

末鹿安然 提交于 2019-12-02 03:59:27
问题 Let's say I have a JSON object such as this: [{ name: "A", sub: [ {prop: "1"}, {prop: "2"}, {prop: "3"}, ] }, { name: "B", sub: [ {prop: "7"}, {prop: "8"}, {prop: "9"}, ] }]; How can I get the parent of the element who's prop value is 2 ? jsonpath.query(data, "$..[?(@.prop==2)]"); This will return the object itself, but I don't know how to get it's parent. 回答1: I ended up using parent instead of query method. As simple as that. I just missed it when I was reading the docs. 来源: https:/

Adding JsonPath in Android Studio causes non-zero exit value 2 error

回眸只為那壹抹淺笑 提交于 2019-12-02 00:01:25
When I add the JsonPath library to my Android Studio (1.4) project I get an error as following: Error:Execution failed for task ':app:dexDebug'. \> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\JDK_64_bit\bin\java.exe'' finished with non-zero exit value 2 (I added the library via File > Project Structure > Dependencies > Library Dependency > com.jayway.jsonpath:json-path:2.0.0 ) Trying to add MultiDex support for the app as suggested in a few other questions results in a different error: Error:Execution failed for

Using jsonpath to get parent node

隐身守侯 提交于 2019-12-01 22:32:48
问题 Using node JSONPath, how can I get the parent node name from child node value { "store": { "book": [ { "id":"1", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "id":"2", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 } ] } } I use this expression to identify the child node based on value, I want to use this child node to find the parent node $.[?(@.id =="1")] 回答1: You do not specify which implementation of JSON Path, but with both Gatling

Using jsonpath to get parent node

爷,独闯天下 提交于 2019-12-01 20:33:54
Using node JSONPath, how can I get the parent node name from child node value { "store": { "book": [ { "id":"1", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "id":"2", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 } ] } } I use this expression to identify the child node based on value, I want to use this child node to find the parent node $.[?(@.id =="1")] You do not specify which implementation of JSON Path, but with both Gatling (Scala) and JayWay (Java) you can use nested filters to filter by children while returning the parent,

AWS Glue Custom Classifiers Json Path

时光怂恿深爱的人放手 提交于 2019-12-01 19:28:09
I have a set of Json data files that look like this [ {"client":"toys", "filename":"toy1.csv", "file_row_number":1, "secondary_db_index":"4050", "processed_timestamp":1535004075, "processed_datetime":"2018-08-23T06:01:15+0000", "entity_id":"4050", "entity_name":"4050", "is_emailable":false, "is_txtable":false, "is_loadable":false} ] I have created a Glue Crawler with the following custom classifier Json Path $[*] Glue returns the correct schema with the columns correctly identified. However, when I query the data on Athena... all the data is landing in the first column and the rest of the

Modify JsonNode of unknown JSON dynamically in Java

落花浮王杯 提交于 2019-12-01 18:45:26
I am trying to modify a JSON (of an unknown structure) where the JsonPath and its equivalent XML Xpath is known to me. I have tired using com.jayway.jsonpath.JsonPath library for the same. The problem with JsonPath is, it returns me the value but I am not able to modify the Target Node. Follows is my code snippet for the same JsonPath.read(jsonFile, jsonPath); JsonPath.parse(jsonPath); System.out.println("Author: "+JsonPath.read(jsonFile, jsonPath)); I tried using Jackson as mentioned in previously asked quetion , But it needs to be traversed node by node as follows ((ObjectNode) parent).put

OR operator in JSONPath?

梦想与她 提交于 2019-12-01 16:52:28
Using a single JSONPath expression alone, is it possible to do some kind of 'OR' or '||' operator. For example, these two JSONPath boolean expressions work to check the severity of a log JSON file: $..log[?(@.severity == 'WARN')] $..log[?(@.severity == 'Error')] But I'd like to do something logically similar to: $..log[?(@.severity == 'WARN' or @.severity == 'Error')] //this is not correct Is there any way to do this? From the JSONPath page : [,] - Union operator in XPath results in a combination of node sets. JSONPath allows alternate names or array indices as a set. Try $..log[?(@.severity =

kubectl: Use custom-columns output with maps

天大地大妈咪最大 提交于 2019-12-01 13:08:54
I want to get the specific value of an annotation into a kubectl custom columns field. I can get all the current annotations on a resource like so: kubectl get pvc -o custom-columns=NAME:.metadata.name,"ANNOTATIONS":.metadata.annotations -n monitoring This returns a map: NAME ANNOTATIONS prometheus-k8s-db-prometheus-k8s-0 map[pv.kubernetes.io/bind-completed:yes pv.kubernetes.io/bound-by-controller:yes volume.beta.kubernetes.io/storage-provisioner:kubernetes.io/aws-ebs] prometheus-k8s-db-prometheus-k8s-1 map[pv.kubernetes.io/bind-completed:yes pv.kubernetes.io/bound-by-controller:yes volume

filter the Json according to string in an array in JSONPATH

戏子无情 提交于 2019-12-01 11:07:08
I have a situation where I have json String that has a child as Array that contains only Strings. Is there as way I can get the object reference of the arrays that contains a specific String. Example: { "Books":{ "History":[ { "badge":"y", "Tags":[ "Indian","Culture" ], "ISBN":"xxxxxxx", "id":1, "name":"Cultures in India" }, { "badge":"y", "Tags":[ "Pre-historic","Creatures" ], "ISBN":"xxxxxxx", "id":1, "name":"Pre-historic Ages" } ] } } To Achieve: From the above JSON String, need to get all books in History which contains "Indian" inside the "tags" list. I am using JSONPATH in my project but

解析复杂的嵌套数据结构-jsonpath

旧时模样 提交于 2019-12-01 08:38:39
JsonPath是一种简单的方法来提取给定JSON文档的部分内容。 JsonPath有许多编程语言,如Javascript,Python和PHP,Java。 JsonPath提供的json解析非常强大,它提供了类似正则表达式的语法,基本上可以满足所有你想要获得的json内容。 Json结构清晰,可读性高,复杂度低,非常容易匹配,其结合方式类似Xpath,为了方便记忆 下表中列出了对应了JSONPath以及对应的XPath用法。 XPath JSONPath 描述 / $ 根节点 . @ 现行节点 / .or[] 取子节点 .. n/a 取父节点,Jsonpath未支持 // .. 就是不管位置,选择所有符合条件的条件 * * 匹配所有元素节点 @ n/a 根据属性访问,Json不支持,因为Json是个Key-value递归结构,不需要属性访问。 [] [] 迭代器标示(可以在里边做简单的迭代操作,如数组下标,根据内容选值等) \| [,] 支持迭代器中做多选。 [] ?() 支持过滤操作. n/a () 支持表达式计算 () n/a 分组,JsonPath不支持 使用规则 JsonPath表达式可以使用点表示法 $.store.book [0].title 或括号表示法 $['store']['book'][0]['title'] 前面我们提到了jsonpath目前支持多种语言