{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
Run Code Online (Sandbox Code Playgroud)
如果我需要所有书籍的作者和书名怎么办?就像如果我只想要这本书的一些细节而不是拥有关于这本书的完整数据,我怎样才能得到它?
太长了;与 一起使用时,以下 JSON 路径对我不起作用pyspark.sql.functions.get_json_object。
$.Blocks[?(@.Type=='LINE')].Confidence
Run Code Online (Sandbox Code Playgroud)
长版...
我想按单行内的数组进行分组
例如,对于下面的结构
root
|--id: string
|--payload: string
Run Code Online (Sandbox Code Playgroud)
的值payload是一个表示 json 块的字符串,其结构如下所示
{
"Blocks": [
{
"Type": "LINE",
"Confidence": 90
},
{
"Type": "LINE",
"Confidence": 98
},
{
"Type": "WORD",
"Confidence": 99
},
{
"Type": "PAGE",
"Confidence": 97
},
{
"Type": "PAGE",
"Confidence": 89
},
{
"Type": "WORD",
"Confidence": 99
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想按类型汇总所有置信度,以便我们得到以下新列......
{
"id": 12345,
"payload": "..."
"confidence": [
{
"Type": "WORD",
"Confidence": [
99,
99
]
},
{ …Run Code Online (Sandbox Code Playgroud) 我正在做集成测试,返回值是一个json对象数组。下面这行代码匹配没有错误:
mockMvc.perform(MockMvcRequestBuilders.get(uri)
.param("name", text)
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].name", Matchers.containsString("div3")));
Run Code Online (Sandbox Code Playgroud)
但是当我更改$[0].name为时$[*].name出现错误
java.lang.AssertionError: JSON path "$[*].name"
Expected: a string containing "div3"
but: was a net.minidev.json.JSONArray (<["Testing Custom Searches div3: 1","Testing Custom Searches div3: 4","Testing Custom Searches div3: 7","Testing Custom Searches div3: 10","Testing Custom Searches div3: 13","Testing Custom Searches div3: 16","Testing Custom Searches div3: 19"]>)
Run Code Online (Sandbox Code Playgroud)
我一直在四处寻找,但没有找到答案...有没有办法检查每个 *.name 元素是否包含给定的子字符串?
在我的istio-system命名空间中,我有以下秘密
\xe2\x96\xb6 k get secret istio-ca-secret -o yaml\napiVersion: v1\ndata:\n ca-cert.pem: LS0tLS1CR...\n ca-key.pem: LS0..\n cert-chain.pem: ""\n key.pem: ""\n root-cert.pem: ""\nRun Code Online (Sandbox Code Playgroud)\n虽然以下查询有效:
\nkubectl get secret istio-ca-secret -n istio-system -o jsonpath="{.data}"\n{"ca-cert.pem":"LS0t=...","ca-key.pem":"LS0tLS1","cert-chain.pem":"","key.pem":"","root-cert.pem":""}% \nRun Code Online (Sandbox Code Playgroud)\n我执行以下命令试图只获取值,但ca-cert.pem什么也不返回
kubectl get secret istio-ca-secret -n istio-system -o jsonpath="{.data.ca-cert.pem}"\nRun Code Online (Sandbox Code Playgroud)\n这是为什么?
\n我有一个以下格式的JavaScript对象
{
"Node1": [
{
"Node2": "node2detail1",
"Node3": "node3detail1",
"Node4": [
"node4detail1",
]
},
{
"Node2": "node2detail2",
"Node3": "node3detail2",
"Node4": [
"node4detail2",
]
},
{
"Node2": "node2detail3",
"Node3": "node3detail3",
"Node4": [
"node4detail3",
]
}
]}
Run Code Online (Sandbox Code Playgroud)
是否可以编写一个jsonpath表达式,该表达式将导致以下格式的JavaScript对象?目的是按键过滤.
{
"Node1": [
{
"Node2": "node2detail1",
"Node3": "node3detail1",
},
{
"Node2": "node2detail2",
"Node3": "node3detail2",
},
{
"Node2": "node2detail3",
"Node3": "node3detail3",
}
]}
Run Code Online (Sandbox Code Playgroud) 我正在使用json-pathcom.jayway.jsonpath:2.4.0`
爪哇代码:
public static void main( String[] args )
{
JSONObject jObject =new JSONObject("{\r\n \"structure\": {\r\n \"tables\": {\r\n \"category\": \"vehicle\"\r\n }\r\n },\r\n \"data\": {}\r\n}") ;
Object jsonPathArray = JsonPath.read(jObject,"$.structure.tables");
System.out.println(jsonPathArray);
}
Run Code Online (Sandbox Code Playgroud)
例外:
Exception in thread "main" com.jayway.jsonpath.PathNotFoundException: Expected to find an object with property ['structure'] in path $ but found 'org.json.JSONObject'. This is not a json object according to the JsonProvider: 'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
at com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:71)
at com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:62)
at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:53)
at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:61)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:187)
at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:102)
at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:89)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:488) …Run Code Online (Sandbox Code Playgroud) 从 JsonPath 对象中提取数据时得到 null,下面是 json 响应数据
{
"status": "OK",
"header": {
"headerAttributes": {}
},
"errors": [],
"payload": {
"totalCount": 0,
"returnTerms": []
}
}
Run Code Online (Sandbox Code Playgroud)
从“totalCount”中提取值的java方法
public void getjsonValue() {
JsonPath jsonPathEvaluator = response.jsonPath();
System.out.println(jsonPathEvaluator.get("$['payload']['totalCount']"));
}
Run Code Online (Sandbox Code Playgroud) 使用 kubectl 时找不到状态 jsonpath。pod json 有一个状态字段,但它是一个数组。
kubectl get pods --column=Status:.status[*]
Run Code Online (Sandbox Code Playgroud)
数组中有多个元素,如何选择一个来反映真实 Pod 状态?
jsonpath ×8
json ×2
kubectl ×2
kubernetes ×2
java ×1
javascript ×1
mockmvc ×1
pyspark ×1
rest-assured ×1
spring-boot ×1
testng ×1