是否可以验证JSONPath表达式? [英] Is it possible to validate a JSONPath expression?

查看:184
本文介绍了是否可以验证JSONPath表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以验证JSONPath表达式.

I want to know if it's possible to validate a JSONPath expression.

我的JSONPath是$.phoneNumbers[:1].type

My JSONPath is $.phoneNumbers[:1].type

我的json如下:

{      
  "phoneNumbers": [
     {
       "type"  : "iPhone",
       "number": "0123-4567-8888"
     },
     {
       "type"  : "home",
       "number": "0123-4567-8910"
     }
  ]
}

我想知道我是否使用正确/有效的JSONPath表达式.

I want to know if I am using the right/valid JSONPath expression.

推荐答案

@Parag A-我刚刚编写了一个JavaScript库,您可以通过该库使用XPath(相对于JSONPath进行标准化)来查询JSON结构.使用此XPath评估程序,您可以粘贴JSON结构并就地验证XPath查询:

@Parag A - I just wrote a javascript library with which you can query JSON structure with XPath (which is standardised as opposed to JSONPath). Using this XPath evaluator, you can paste in your JSON structure and validate your XPath queries, in-place:

http://www.defiantjs.com/#xpath_evaluator

将您的问题和答案放入javascript代码中,看起来像这样:

Putting your question and the answer in javascript code, it'll look something like this:

var obj = {      
  "phoneNumbers": [
     {
       "type"  : "iPhone",
       "number": "0123-4567-8888"
     },
     {
       "type"  : "home",
       "number": "0123-4567-8910"
     }
  ]
};

var qry = JSON.search(obj, '//phoneNumbers[1]/type');
// qry[0] = 'iPhone'

Defiant扩展了全局对象JSON,并且search方法始终返回具有匹配选择的数组(如果未找到匹配项,则为空数组).

Defiant extends the global object JSON and the search method always returns an array with matching selections (empty array if no matches were found).

这篇关于是否可以验证JSONPath表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆