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

查看:23
本文介绍了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)

快速谷歌搜索表明人们已经考虑过并实施了一些事情(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 格式对于我的想法来说可能过于通用.. 想要查询语言而不是根据需要直接执行求和/等函数的原因是我希望根据用户输入动态构建查询.有点像我们不需要 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..)

推荐答案

好的,怎么样:

它们似乎都在进行中,但在某种程度上是有效的.它们在概念上也类似于 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天全站免登陆