是否有用于JSON的查询语言,该语言允许访问父节点并具有多选功能? [英] Is there a query language for JSON which allow access to parent node and has multiselect?

查看:147
本文介绍了是否有用于JSON的查询语言,该语言允许访问父节点并具有多选功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSON的查询语言很多,例如JMES Path和JSON Path,但是我发现没有一种对我感兴趣,例如JSON Path不允许多选查询(我无法返回具有不同类型元素[汽车,飞机,船形]的列表),并且与JSON Path相比,JMES Path确实更简单,并且允许多选,但不允许访问到父节点,例如..或parent(@)或$(作为源). 因此,我希望一种语言能够同时实现这两种语言,如果可能的话,查询语言很简单,例如JMES Path,但是如果只有一种并且是最困难的一种语言,那么我会接受的!

There are many query languages for JSON, such as JMES Path and JSON Path, but none of the ones I've found interest me, e.g. JSON Path doesn't allow multiselect query (I can't return a list with different type element [car, plane, boat]) and JMES Path is really simpler compare to the JSON Path and allow the multiselect but doesn't allow the access to the parent node like .. or parent(@) or $(for the source). So I want a language which can do both, if it's possible a query language simple as JMES Path, but if there is only one and it the most difficult one it's okay I will take it !

PS:我使用JavaScript!

PS: I work in javascript !

推荐答案

是一种JSON查询语言,与JSONPath相似,但具有图灵完备的编程语言的全部通用性. jq包含所有JSON,并且其许多构造类似于JSON.

jq is a JSON Query language with some resemblance to JSONPath, but with the full generality of a Turing-complete programming language. jq subsumes all of JSON, and many of its constructs are JSON-like.

可以在jq中处理涉及父母"和孩子"的问题的一种方法是使用jq路径,这就是JSON数组,其所有元素都是JSON字符串(对应于键名)或整数(对应于数组的索引).因此,如果$p是JSON文档某些子组件的路径,则其父级的路径将是$p[:-1].

One of the ways in which problems involving "parents" and "children" can be handled in jq is using jq paths, which are nothing other than JSON arrays all of whose elements are either JSON strings (corresponding to key names) or integers (corresponding to indices into an array). Thus if $p is the path to some sub-component of a JSON document, then the path to its parent would be $p[:-1].

但是,实际上,无需使用完整路径就可以更轻松地解决涉及父母和/或孩子的许多问题.特别注意,to_entries可以与JSON对象和JSON数组一起使用.

In practice, though, many problems involving parents and/or children can more easily be solved without using full paths. Note in particular that to_entries can be used with both JSON objects and JSON arrays.

主网站包括一个教程,手册和一个Wiki,其中包含一个常见问题解答,食谱,语言描述"和JSONPath用户指南.

The main website includes a tutorial, manual, and a Wiki, which has a FAQ, Cookbook, a "Language Description", and a guide for JSONPath users.

在stackoverflow上,当前有2,000多个问题具有标签.另请参见 http://rosettacode.org/wiki/Category:Jq

Here on stackoverflow, there are currently over 2,000 questions that have the jq tag. See also http://rosettacode.org/wiki/Category:Jq

这篇关于是否有用于JSON的查询语言,该语言允许访问父节点并具有多选功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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