JSON是否有查询语言? [英] Is there a query language for JSON?

查看:193
本文介绍了JSON是否有查询语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在(大致)SQL或类似XQuery的语言来查询JSON?

Is there a (roughly) SQL or XQuery-like language for querying JSON?

我正在考虑非常小的数据集,这些数据集可以很好地映射到JSON,可以轻松回答诸如"Y> 3时X的所有值是什么"之类的查询或执行常规的SUM/COUNT类型操作

I'm thinking of very small datasets that map nicely to JSON where it would be nice to easily answer queries such as "what are all the values of X where Y > 3" or to do the usual SUM / COUNT type operations.

作为完全虚构的示例,如下所示:

As completely made-up example, something like this:

[{"x": 2, "y": 0}}, {"x": 3, "y": 1}, {"x": 4, "y": 1}]

SUM(X) WHERE Y > 0     (would equate to 7)
LIST(X) WHERE Y > 0    (would equate to [3,4])

我认为这将在客户端和服务器端均有效,并将结果转换为适当的特定于语言的数据结构(或可能保留为JSON)

I'm thinking this would work both client-side and server-side with results being converted to the appropriate language-specific data structure (or perhaps kept as JSON)

快速Google搜索表明人们已经考虑了这一点并实施了一些措施( JAQL ),但似乎还没有出现标准用法或库集.虽然每个功能单独实现起来都很简单,但是如果有人已经正确地实现了,我就不想重新发明轮子了.

A quick Googling suggests that people have thought about it and implemented a few things (JAQL), but it doesn't seem like a standard usage or set of libraries has emerged yet. While each function is fairly trivial to implement on its own, if someone has already done it right I don't want to re-invent the wheel.

有什么建议吗?

这的确是个坏主意,或者JSON可能对于我正在考虑的格式来说太通用了.想要查询语言而不是直接根据需要直接执行sum/etc函数的原因是,我希望基于用户输入动态构建查询. Kinda喜欢这样的论点:我们不需要SQL,我们只需编写所需的函数即可".最终,这要么变得一发不可收拾,要么随着您对SQL的推论不断深入而最终编写出自己的SQL版本. (好吧,我知道这是一个愚蠢的争论,但您明白了.)

This may indeed be a bad idea or JSON may be too generic a format for what I'm thinking.. The reason for wanting a query language instead of just doing the summing/etc functions directly as needed is that I hope to build the queries dynamically based on user-input. Kinda like the argument that "we don't need SQL, we can just write the functions we need". Eventually that either gets out of hand or you end up writing your own version of SQL as you push it further and further. (Okay, I know that is a bit of a silly argument, but you get the idea..)

推荐答案

当然,如何:

  • JsonPath.
  • Json Query

它们似乎都在进行中,但是在某种程度上仍在工作.从概念上讲,它们还类似于XPath和XQuery.即使XML和JSON具有不同的概念模型(层次结构与对象/结构).

They all seem to be a bit work in progress, but work to some degree. They are also similar to XPath and XQuery conceptually; even though XML and JSON have different conceptual models (hierarchic vs object/struct).

EDIT -2015年9月:实际上,现在有 JSON指针允许非常简单有效地遍历JSON内容的标准.它不仅是正式指定的,而且还受许多JSON库的支持.因此,我将其称为实际真正有用的标准,尽管由于其有限的表达性,它本身可能会被视为查询语言,也可能不会被视为查询语言.

EDIT Sep-2015: Actually there is now JSON Pointer standard that allows very simple and efficient traversal of JSON content. It is not only formally specified, but also supported by many JSON libraries. So I would call it actual real useful standard, although due to its limited expressiveness it may or may not be considered Query Language per se.

这篇关于JSON是否有查询语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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