我正在尝试使用jsonPath和pick函数来确定是否需要根据当前域运行规则.我正在做的简化版本是:
global
{
dataset shopscotchMerchants <- "https://s3.amazonaws.com/app-files/dev/merchantJson.json" cachable for 2 seconds
}
rule checkdataset is active
{
select when pageview ".*" setting ()
pre
{
merchantData = shopscotchMerchants.pick("$.merchants[?(@.merchant=='Telefora')]");
}
emit
<|
console.log(merchantData);
|>
}
Run Code Online (Sandbox Code Playgroud)
我期望的控制台输出是telefora对象,而是从json文件中获取所有三个对象.
如果不是商家=='Telefora'我使用merchantID == 16那么它的效果很好.我认为jsonPath也可以匹配字符串.虽然上面的例子没有搜索json的merchantDomain部分,但我遇到了同样的问题.
{
"response_time": 0.014376163482666016,
"applications": [
{
"api_key": "blted0e7982e1cf62a8",
"name": "gta",
"uid": "gta",
"account_name": "jack"
},
{
"api_key": "blt1423c40d23e4a423",
"name": "cellapp",
"uid": "cellapp",
"account_name": "max"
}
]
}
Run Code Online (Sandbox Code Playgroud)
请帮我提取account_name = max使用Jmeter Json Path Extractor.
假设我有一个简单的json文件,如下所示
{
"log": {
"host": "blah",
"severity": "INFO",
"system": "1"
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Apache Camel,它是Spring XML来处理和路由json文件.我的路由代码看起来像这样:
<route>
<from uri="file:/TESTFOLDER/input"/>
<choice>
<when>
<jsonpath>$.log?(@.severity == 'WARNING')</jsonpath>
<to uri="smtp://(smtpinfo...not important)"/>
</when>
<otherwise>
<to uri="file:/TESTFOLDER/output"/>
</otherwise>
</choice>
</route>
Run Code Online (Sandbox Code Playgroud)
我真正困惑的部分是JSONPath表达式.我上面的表达式甚至在语法上都不正确,因为很难找到你不试图对元素列表进行排序的例子.我的目标是只在日志的严重性为"警告"时发送电子邮件,但我无法提出表达式.
使用简单的Json文件,例如:
{"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "New", "onclick": "CreateNewDoc()"},
{"value": "Open", "onclick": "OpenDoc()"},
{"value": "Close", "onclick": "CloseDoc()"}
]
}
}}
Run Code Online (Sandbox Code Playgroud)
我希望能够使用路径获取JsonArraynamed menuitem:
String path = "menu.popup.menuitem"
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下方法执行此操作:
public static JsonElement fromString(String json, String path) throws JsonSyntaxException {
JsonObject obj = GsonBuilder.create().fromJson(json, JsonObject.class);
String[] seg = path.split(".");
for (String element : seg) {
if (obj != null) {
obj = obj.get(element).getAsJsonObject();
} else {
return null;
}
}
return obj
}
Run Code Online (Sandbox Code Playgroud)
与: …
我有一个嵌套的父/子结构的JSON结构:
{
"type": "site",
"profile_id": "site profile id",
"children": [
{
"type": "dealer",
"profile_id": "dealer profile id",
"children": [
{
"type": "location",
"profile_id": "location profile id",
"children": [
{
"type": "customer",
"profile_id": "customer profile id",
"children": [
{
"type": "farm",
"farm_id": "farm id",
"children": [
{
"type": "field",
"field_id": "field id"
}]}]}]}]}]}
Run Code Online (Sandbox Code Playgroud)
JSONPath中有某种方法可以执行以下操作之一:
如果有profile_id,请给我;如果有farm_id,请给我;如果有,请给我field_id。
如果type = customer,请给我profile_id;如果type = farm,请给我farm_id;如果type = field,请给我field_id
给我每个班级的第n个属性。id实际上是每个类中的第三个属性。这是我最不喜欢的选项,因为我不知道id是否始终是第三个属性。
我有像下面的json字符串
[
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 0
},
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 1
},
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 2
},
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 3
},
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 4
},
{
"topic": "inputTopic",
"key": "0",
"message": "test",
"partition": 0,
"offset": 5
},
{
"topic": "inputTopic",
"key": "0",
"message": …Run Code Online (Sandbox Code Playgroud) 您好,SO社区:)!
我想创建一种方法,该方法将允许用户编辑(或添加)JSON特定值或对象(通过JSONPath在JSON中定位)。下面简单的例子是我的想法。用户始终输入JSON,JSONPath和要更改的值/对象。我正在使用Json.NET库。
方法输入 {json,jsonpath,valuetoedit} || 输出 {new json as string}
输入示例:
{ "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": { …Run Code Online (Sandbox Code Playgroud) Run Code Online (Sandbox Code Playgroud){ "response": { "result": { "Countries": { "row": [ { "no": "1", "FL": [ { "content": "USA", "val": "Country" }, { "content": "Barack Obama", "val": "President" } ] }, { "no": "2", "FL": [ { "content": "Cuba", "val": "Country" }, { "content": "Raul Castro", "val": "President" } ] } ] } } } }
{ presidents: [
{ "name": "Barack Obama"}
]
}
Run Code Online (Sandbox Code Playgroud)
我有一个JSON数组,其中包含4个对象,每个对象都有一个id字段。第四个对象包含两个孩子,每个孩子也都有一个id字段。我只想获取4个顶级孩子的ID;我不希望第4个元素的子代的ID。
这是JSON字符串的简化版本:
[
{
"id": 709709537
},
{
"id": 1104067257
},
{
"id": 2961327618
},
{
"id": 9066007668,
"photo": {
"id": 461295287,
"thumbnails": [
{
"id": 461295307
}
]
}
}
]
Run Code Online (Sandbox Code Playgroud)
使用JSONPath,$..id将获得全部6个id元素,而无法确定它们来自哪个级别,例如
[
709709537,
1104067257,
2961327618,
9066007668,
461295287,
461295307
]
Run Code Online (Sandbox Code Playgroud)
我原本$.id希望给我4个顶级id孩子,但这一无所获。
我研究了许多页面,并尝试使用JSON测试器(例如https://jsonpath.curiousconcept.com/)进行了几次实验,但找不到JSONPath表达式来获取仅前4个子id元素。
是否有一个JSONPath表达式可以让我得到顶级子ID?
我想比较两个jsonPath值是否相等,如下所示:
this.mockMvc.perform(get(requestURL)).andExpect(jsonPath("$.prop1", equalTo(jsonPath("$.prop2"))));
Run Code Online (Sandbox Code Playgroud)
但后来我的测试失败了。该(“ $为prop1”)jsonPath返回正确的价值我想要的,但jsonPath(“$ PROP2。”)不返回该属性的值,而不是像类名:
org.springframework.test.web.servlet.result.JsonPathResultMatchers@7b7aaaf6
谁能给我个主意,我如何执行jsonPath()的toString()方法?我也尝试了jsonPath(“ $。prop2”)。toString(),但也收到了类名。
谢谢高级!
jsonpath ×10
json ×7
apache-camel ×1
c# ×1
gson ×1
java ×1
javascript ×1
jmeter ×1
krl ×1
mocking ×1
spring ×1
typescript ×1
xpath ×1