Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jque

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jque

Query JSON in memory as though it were a Mongo database.

  • 0.1.3
  • PyPI
  • Socket score

Maintainers
1

j q u e

Query JSON in memory as though it were a Mongo database

Installation

pip3 install jque

Usage

import jque

jque accepts a variety of inputs to the constructor.

Pass a list of dicts:

data = jque.jque([
    { "name": "john" }, 
    { "name": "paul" }, 
    { "name": "george" }, 
    { "name": "ringo" }
])

Pass a JSON filename:

DATAFILE = "~/my/big/data.json"
data = jque.jque(DATAFILE)

Now you can query this dataset using Mongo-like syntax:

>>> data.query({ "name": {"$neq": "paul"} })
[
    { "name": "john" },
    { "name": "george" }, 
    { "name": "ringo" }
]

Arguments to query:

ArgDescription
wrap (boolean : True)Whether to wrap the resultant dataset in a new jque object. This allows chaining, like jque.query(...).query(...), if you're the sort of person to do that. Pass False to get back a list instead.

Another example!

data = jque.jque([{
    "_id": "ABC",
    "name": "Arthur Dent",
    "age": 42,
    "current_planet": "earth"
}, {
    "_id": "DE2",
    "name": "Penny Lane",
    "age": 19,
    "current_planet": "earth"
}, {
    "_id": "123",
    "name": "Ford Prefect",
    "age": 240,
    "current_planet": "Brontitall"
}])
teenage_earthlings = data.query({
    "current_planet": {"$eq": "earth"},
    "age": { "$lte": 20, "$gte": 10 }
})

Which returns:

[{
    "_id": "DE2",
    "name": "Penny Lane",
    "age": 19,
    "current_planet": "earth"
}]

Use Python lambdas as a filter:

>>> libraries = jque.jque([
...     {"name": "jque", "language": "Python"}, 
...     {"name": "react", "language": "node"}
... ])
>>> list(libraries.query({
...     'language': lambda x: x[:2] == "Py"
... }))
[{"name": "jque", "language": "Python"}]

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc