有没有类似SQL或XQuery的语言来查询JSON?

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.

作为一个完全虚构的例子,大概是这样的:

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

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)

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.

有什么建议吗?

Edit: 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有不同的概念模型(层次 struct 与对象/ struct ).

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

Json相关问答推荐

使用更高级别架构中的字段值在$def内实现约束

Golang返回的JSON顶级字段是可变的.如何在 struct 中使用

Vega-Lite(Deneb):难以将最小和最大值应用于折线图和文本标签以及线条末尾的点

将JSON数组组织到菜单中

Jolt:数组中两个字符串的连接

报告重复的对象键

使用 serde 和 csv crates 将嵌套的 json 对象序列化为 csv

Jolt 变换 - 如何用字段值重命名字段?

JSON 字段的多个名称

使用 SwiftUI 在 API 调用中解码嵌套 JSON 响应时遇到问题

如果有 1 个元素,如何防止 ConvertFrom-Json 折叠嵌套数组

编写 JSON 日志(log)文件的格式?

如何在 Perl 中将简单的哈希转换为 json?

jquery用json数据填充下拉列表

在 Jersey 服务中使用 JSON 对象

使用绝对或相对路径在 curl 请求中发送 json 文件

gson:将 null 视为空字符串

使用杰克逊创建一个 json 对象

带有方法参数的 WCF webHttpBinding 错误. 最多可以在没有包装元素的情况下序列化一个主体参数

YAML 将 5e-6 加载为字符串而不是数字