JSON的结构化查询语言(在Python中) [英] structured query language for JSON (in Python)

查看:140
本文介绍了JSON的结构化查询语言(在Python中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用输出JSON文件的系统,并且使用Python解析数据并将其显示在UI(PySide)中.我现在想向该系统添加过滤,并且我认为与其编写一个查询系统,而不是编写查询系统,如果有一个用于JSON(在Python中)的查询系统,那将节省很多开发时间.我找到了这个线程:

I am working on a system to output a JSON file and I use Python to parse the data and display it in a UI (PySide). I now would like to add filtering to that system and I think instead of writing a query system, if there was one out there for JSON (in Python), that would save me a lot of development time. I found this thread:

是否存在JSON的查询语言?

但是对于基于Web的系统而言,更多.关于Python等效的任何想法吗?

but that's more for a Web-based system. Any ideas on a Python equivalent?

编辑[为了清楚]:

我将要生成的数据的格式如下:

The format the data that I'll be generating is like this:

{
    "Operations": [
    {
        "OpID": "0", 
        "type": "callback", 
        "stringTag1": "foo1", 
        "stringTag2": "FooMsg", 
        "Children": [...],
        "value": "0.000694053"
   },
   {
        "OpID": "1", 
        "type": "callback", 
        "stringTag1": "moo1", 
        "string2": "MooMsg", 
        "Children": [...],
        "value": "0.000468427"
   }
}

其中子项"可以是同一事物的嵌套数组(其他操作).该系统将被构建为允许用户向数据添加自己的标签.我希望有一个查询系统,该系统也允许用户定义自己的过滤器",因此存在有关查询语言的问题.

Where 'Children' could be nested arrays of the same thing (other operations). The system will be built to allow users to add their own tags as well to the data. My hope was to have a querying system that would allow users to define their own 'filters' as well, hence the question about the querying language. If there was something that would let me do something like "SELECT * WHERE "type" == "callback" and get the requisite operations back, that would be great.

Pync的建议很有趣,我来看一下.

The suggestion of Pync is interesting, I'll give that a look.

推荐答案

我对此进行了一些思考,我倾向于一些不太具体的东西,例如"JSON查询语言",并认为它更通用.我记得与C#一起工作时曾记得他们有一个称为 LINQ 的通用查询系统来处理这类查询问题.

I thought about this a little bit, and I lean towards something less specific such as a "JSON Query Language" and considered something more generic. I remembered from working with C# a bit that they had a somewhat generic querying system called LINQ for handling these sort of querying issues.

Python似乎有一个类似的名称 Pynq ,它支持基本查询,例如:

It looks as though Python has something similar called Pynq which supports basic querying such as:

filtered_collection = From(some_collection).where("item.property > 10").select_many()

它甚至似乎具有一些基本的聚合函数.尽管不是特定于JSON,但我认为这至少是查询的一个很好的起点.

It even appears to have some basic aggregation functions. While not being specific to JSON, I think it's a least a good starting point for querying.

这篇关于JSON的结构化查询语言(在Python中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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