Skip to main content

jsonLookup

Searching in MySQL JSON field in Django

Challenge

MySQL has introduced JSON fields in MySQL Server 5.7, Currently it works well with jsonfield for Data Saving and retrieval. The problem that Searching can only be done through LIKE operator which isn't convinent for all function.

Objective

Creating a new custom lookup operator "has" for Django that will support JSON Search in MySQL.

Installation

Install the Package

$ pip install jsonLookup

Register to JSONFields

from jsonLookup import hasLookup,jcontainsLookup
JSONField.register_lookup(hasLookup)
JSONField.register_lookup(jcontainsLookup)

Write your JSON queries

# Create test objects
User.objects.create(name="Ahmed",properties={"city":"Giza","Address":{"district":"Ahram","Code":11263}})
User.objects.create(name="Mohamed",properties={"city":"Cairo","Address":{"district":"Helipolis","Code":11351}})
# Run first query
q = User.objects.filter(properties__has="$.city=Giza")
print q[0].name
"Ahmed"
# Run Second query
q= User.objects.filter(properties__has="$.Address.Code=11351")
print q[0].name
"Mohamed"

Metadata

Release files for jsonLookup 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonLookup 0.9.0
File Size Uploaded
jsonLookup-0.9.0.tar.gz 3.0 kB Details

Release files / jsonLookup-0.9.0.tar.gz

Download URL jsonLookup-0.9.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
95bb1cd51e04e21c1b5a70ec5faa597b8435cb94da868fbbd5d1550fc7c88432
BLAKE2b-256 checksum
How to use checksums
eb384c23a9803fd4726d25e708f76a3d0164573d21d2ec5ccbd8ec8fcbec50e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/2.7.17

Release history Release notifications | RSS feed

This release

0.9.0 This release

1 release file

0.8.0

1 release file

0.7.5

1 release file

0.6.0

1 release file

0.5.2

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page