标签: jsonpath

如何使用JSON路径引用根密钥?

我有这样的数据:

{"key": {"name":"hi", "size":10}}
Run Code Online (Sandbox Code Playgroud)

"关键"是一种动态价值.它不是固定的.我可以访问namesize使用此JSON路径:

*.name
*.size
Run Code Online (Sandbox Code Playgroud)

如何使用JSON Path获取"key"本身的值?*给我的数据的整个行,都$@给予我在解析器"元素没有找到".

我正在尝试使用JSON输入步骤在Pentaho中执行此操作.

json pentaho jsonpath

7
推荐指数
1
解决办法
5936
查看次数

处理rails 3控制器中的jsonp

我希望我的控制器操作能够处理来自jquery的jsonp请求$.getJSON.在我的控制器操作中,我有以下respond_to块:

respond_to do |format|
  format.html { render json: {:items_by_tag => @tagged_item_list}}
  if params[:callback]
        format.js { render :json => {:items_by_tag => @tagged_item_list}.to_json, :callback => params[:callback] }
  else
        format.json { render json: {:items_by_tag => @tagged_item_list}}
  end
end
Run Code Online (Sandbox Code Playgroud)

但是SyntaxError:invalid label当我打电话给网址时,我正在收到$.getJSON.我的网址是形式的http://myservice.com?param1=a&param2=b&callback=?.
我的代码导致jsonp失败的问题是什么?

javascript jquery cross-domain jsonpath ruby-on-rails-3

7
推荐指数
1
解决办法
6277
查看次数

有没有办法在 JSONPath 中获取字符串值的子字符串?

基本上,我需要使用 JSONPath 获取字符串值的一部分。我无法先使用 JSONPath 获取完整值,然后使用另一种语言获取它的一部分。

有没有办法在 JSONPath 中做到这一点?

json jsonp jsonpath

7
推荐指数
1
解决办法
4081
查看次数

JsonPath:如果满足条件,则选择根级别字段

鉴于以下Json输入:

{ 
  "category": "fiction",
  "author": "Evelyn Waugh",
  "title": "Sword of Honour",
  "price": 12.99
}
Run Code Online (Sandbox Code Playgroud)

如果作者匹配例如给定名称,我需要选择作者字段.Evelyn Waugh.我正在努力为此编写JsonPath表达式.我尝试了以下但没有成功.谁能建议正确的表达方式?

$.author?(@ == 'Evelyn Waugh')
$.?(@.author == 'Evelyn Waugh')
$..?(@.author == 'Evelyn Waugh')
Run Code Online (Sandbox Code Playgroud)

json filter input-filtering jsonpath

7
推荐指数
1
解决办法
2258
查看次数

JsonPath表达式使用正则表达式进行过滤

我们正在使用一个使用jayway库来评估JSONpath表达式的工具.Javascript似乎不适用它.在这种情况下,如何在JSONPath中使用正则表达式.例如,在下面的示例中,我想过滤其标题中包含"Sword"一词的所有书名:

{
    "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)

regex json jsonpath

7
推荐指数
1
解决办法
2万
查看次数

SelectTokens中的JSON.Net"无法读取查询运算符"

我正在尝试使用JSON.Net中的SelectTokens方法从magicthegathering.io获得的一些JSON中获取一些信息.但是,当我尝试这样做时,我收到错误"无法读取查询运算符".

这是我正在使用的代码:

JToken jtoken = JToken.Parse(
    @"{""cards"":[{""name"":""Krark-Clan Engineers"",""manaCost"":""{3}{R}"",""cmc"":4,""colors"":[""Red""],""type"":""Creature — Goblin Artificer"",""types"":[""Creature""],""subtypes"":[""Goblin"",""Artificer""],""rarity"":""Uncommon"",""set"":""5DN"",""text"":""{R}, Sacrifice two artifacts: Destroy target artifact."",""flavor"":""\""Well, I jammed the whatsit into the whackdoodle, but I think I broke the thingamajigger.\"""",""artist"":""Pete Venters"",""number"":""70"",""power"":""2"",""toughness"":""2"",""layout"":""normal"",""multiverseid"":50201,""imageUrl"":""http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=50201&type=card"",""foreignNames"":[{""name"":""???????"",""language"":""Chinese Simplified"",""multiverseid"":81620},{""name"":""Ingénieurs du clan Krark"",""language"":""French"",""multiverseid"":80795},{""name"":""Ingenieure des Krark-Clans"",""language"":""German"",""multiverseid"":80960},{""name"":""Ingegneri di Krark-Clan"",""language"":""Italian"",""multiverseid"":81290},{""name"":""????????"",""language"":""Japanese"",""multiverseid"":80630},{""name"":""Engenheiros do Clã-de-Krark"",""language"":""Portuguese (Brazil)"",""multiverseid"":81455},{""name"":""Ingenieros del clan Krark"",""language"":""Spanish"",""multiverseid"":81125}],""printings"":[""5DN""],""originalText"":""{R}, Sacrifice two artifacts: Destroy target artifact."",""originalType"":""Creature — Goblin Artificer"",""legalities"":[{""format"":""Commander"",""legality"":""Legal""},{""format"":""Freeform"",""legality"":""Legal""},{""format"":""Legacy"",""legality"":""Legal""},{""format"":""Mirrodin Block"",""legality"":""Legal""},{""format"":""Modern"",""legality"":""Legal""},{""format"":""Prismatic"",""legality"":""Legal""},{""format"":""Singleton 100"",""legality"":""Legal""},{""format"":""Tribal Wars Legacy"",""legality"":""Legal""},{""format"":""Vintage"",""legality"":""Legal""}],""id"":""a4d05fd27ec5d7df470e91218f1ca885eda4f0c6""}]}"
);

var foundTokens = jtoken.SelectTokens(@"$..cards[?(@.name=""Krark - Clan Engineers"")].imageUrl", true);
if (foundTokens.Any())
{
    string selected = …
Run Code Online (Sandbox Code Playgroud)

json.net jsonpath

7
推荐指数
1
解决办法
712
查看次数

Sublime text 3插件获取JSON路径

我在sublime text 3中使用插件或技术来获取我将在编辑器窗口中选择的json元素的完全限定路径.

有些想法:http://jsonpath.com/

我想在某个地方得到一个我可以复制的结果,我只是想将它用于文档,而不是以编程方式.它不需要是https://github.com/jayway/JsonPath标准,只需要生成一个可读/有意义的元素路径.

json jsonpath sublimetext3 sublime-text-plugin visual-studio-code

7
推荐指数
2
解决办法
1807
查看次数

jsonpath 在与数组索引无关的 jsonarray 中查找字符串值

我有一个数组的 Gatling JSON 对象。该对象包含错误消息,例如

"error": [
    {
      "errorCode": "111",
      "errorMessage": "very dynamic error :- at [Source: java.io.PushbackInputStream@5d0edb12; line: 6, column: 6]; nested exception is com.fasterxml.jackson.core.JsonParseException: "
    },
    {
      "errorCode": null,
      "errorMessage": "Fixed Error Message"
    },
    {
      "errorCode": "112",
      "errorMessage": "Again some error message"
    }
  ]
Run Code Online (Sandbox Code Playgroud)

我正在检查 jsonpath 作为

($.error[1].errorMessage).is("Fixed Error Message")

但是,不同的 API 有不同的错误对象,固定的 errorMessage 可以放在数组中的任何索引位置。

如何动态检查 jsonArray 中是否存在固定的 errorMessage 而不用担心 arrayIndex ?

我可以做一个独立匹配字符串与数组元素而不提及数组索引的查询,如下所示? ($.error[*].errorMessage).is("Fixed Error Message")

arrays json scala jsonpath gatling

7
推荐指数
1
解决办法
8010
查看次数

REST-Assured - 用于获取值列表的JsonPath

我正在使用REST-Assured来测试一些RESTful Web服务.这是我的JSON:

{
    "status":true,
    "responseData":{
        "orderLevelReasons":[
            {
                "reasons":[
                    {
                        "reasonId":"129cfea8-b022-4dc8-9811-222a324f46aa",
                        "reasonName":"COD Amount Mismatch"
                    },
                    {
                        "reasonId":"a881fd5c-626e-438c-8026-646aa2a19098",
                        "reasonName":"Gave wrong information"
                    },
                    {
                        "reasonId":"543d438a-88cc-487c-86e4-19eecefa9ca7",
                        "reasonName":"Late delivery"
                    },
                    {
                        "reasonId":"080cd7c1-7a37-48ad-9090-57286d93ea41",
                        "reasonName":"Parcel not received"
                    },
                    {
                        "reasonId":"5ca3d9b4-0fa2-49da-a534-a6f2e7eccc07",
                        "reasonName":"Staff did not inform about the parcel arrival"
                    }
                ],
                "issueName":"ISSUE TYPE 1",
                "issueId":"0c2c37a6-62b6-4c28-ab6c-566487d045bd",
                "hint":""
            },
            {
                "reasons":[
                    {
                        "reasonId":"129cfea8-b022-4dc8-9811-222a324f46aa",
                        "reasonName":"COD Amount Mismatch"
                    },
                    {
                        "reasonId":"14975b5d-23fb-4735-8082-2e02d6335788",
                        "reasonName":"Data issue"
                    },
                    {
                        "reasonId":"7e6e8446-3774-4589-9171-8e7ab0a7f73b",
                        "reasonName":"Delivery BOY did not inform before delivering"
                    },
                    {
                        "reasonId":"543d438a-88cc-487c-86e4-19eecefa9ca7",
                        "reasonName":"Late delivery"
                    },
                    {
                        "reasonId":"080cd7c1-7a37-48ad-9090-57286d93ea41",
                        "reasonName":"Parcel …
Run Code Online (Sandbox Code Playgroud)

java jsonpath rest-assured rest-assured-jsonpath

7
推荐指数
1
解决办法
2295
查看次数

如何使用kubectl和jsonpath将configmap的内容保存到文件中?

我正在尝试将configmap的内容保存到本地硬盘驱动器上的文件中。Kubectl支持使用JSONPath进行选择,但是我找不到只需要选择文件内容的表达式。

configmap是使用以下命令创建的

kubectl create configmap my-configmap --from-file=my.configmap.json=my.file.json
Run Code Online (Sandbox Code Playgroud)

当我跑步

kubectl describe configmap my-configmap
Run Code Online (Sandbox Code Playgroud)

我看到以下输出:

Name:         my-configmap 
Namespace:    default 
Labels:       <none> 
Annotations:  <none>

Data
==== 
my.file.json:
---- 
{
    "key": "value" 
} 
Events:  <none>
Run Code Online (Sandbox Code Playgroud)

我得到的最深入的信息,因此仅选择文件内容是这样的:

 kubectl get configmap my-configmap -o jsonpath="{.data}"
Run Code Online (Sandbox Code Playgroud)

哪个输出

map[my.file.json:{
    "key": "value"
}]
Run Code Online (Sandbox Code Playgroud)

我想要的输出是

{
  "key": "value"
}
Run Code Online (Sandbox Code Playgroud)

JSONPath难题的最后一部分是什么?

jsonpath kubernetes kubectl configmap

7
推荐指数
1
解决办法
5011
查看次数