neosqlite.collection.json_helpers module

class neosqlite.collection.json_helpers.NeoSQLiteJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

Custom JSON encoder for NeoSQLite that handles Binary, ObjectId, and datetime objects.

default(obj)[source]

Encodes Binary, ObjectId, and datetime objects for JSON serialization.

Parameters:

obj – The object to encode.

Returns:

The encoded object suitable for JSON serialization.

neosqlite.collection.json_helpers.neosqlite_json_dumps(obj: Any, **kwargs) str[source]

Custom JSON dumps function that handles Binary objects.

Parameters:
  • obj – Object to serialize

  • **kwargs – Additional arguments to pass to json.dumps

Returns:

JSON string representation

neosqlite.collection.json_helpers.neosqlite_json_dumps_for_sql(obj: Any, **kwargs) str[source]

Custom JSON dumps function for SQL query parameters that handles Binary objects using compact formatting to match SQLite’s json_extract behavior.

Parameters:
  • obj – Object to serialize

  • **kwargs – Additional arguments to pass to json.dumps

Returns:

JSON string representation in compact format

neosqlite.collection.json_helpers.neosqlite_json_loads(s: str, **kwargs) Any[source]

Custom JSON loads function that handles Binary objects and ISO date strings.

For MongoDB compatibility, ISO 8601 date strings are automatically converted back to datetime objects, matching MongoDB’s behavior where dates are stored as BSON Date type and returned as datetime objects.

Parameters:
  • s – JSON string to deserialize

  • **kwargs – Additional arguments to pass to json.loads

Returns:

Deserialized object