Python Package Index

local Python Package Index (PyPI)

corelibs-json (1.0.1)

Published 2026-02-03 15:16:31 +09:00 by clemens

Installation

pip install --index-url https://git.gullevek.org/api/packages/PyPI/pypi/simple/ --extra-index-url https://pypi.org/simple corelibs-json

About this package

CoreLibs Json utilities

CoreLibs Python Json support

This is part of the Python CoreLibs

Overview

Various support for JSON like jmes path search and support function for json dump

Install

uv add --index opj-pypi=https://git.egplusww.jp/api/packages/PyPI/pypi/simple/ corelibs-json

Usage

The following modules exist

  • corelibs_json.jmespath_support
  • corelibs_json.json_support

jmespath_support usage

jmespath search support methods

from corelibs_json.jmespath_support import jmespath_search

jmespath_search

Use jmespath to search in a dictionary

def jmespath_search(search_data: dict[Any, Any] | list[Any], search_params: str) -> Any:

Will throw ValueError if an error is encountered

Example:

See: https://jmespath.org/

json_support usage

Various support methods for json dumping

from corelibs_json.json_support import DateTimeEncoder, default_isoformat, json_dumps, modify_with_jsonpath

DateTimeEncoder (Class)

Can be used as the "cls" argument in "json.dumps", makes sure a date is in the isoformat so it does not trip the json encoding

Example:

import json
from corelibs_json.json_support import DateTimeEncoder

out = json.dumps(incoming, cls=DateTimeEncoder)

default_isoformat (method)

Can be used as the "default" arugment in "json.dumps", makes sure a date is in the isoformat so it does not trip the json encoding

Example:

import json
from corelibs_json.json_support import default_isoformat

out = json.dumps(incoming, default=default_isoformat)

json_dumps

Dump data in a safe format with ensure ascii and default everything to string

def json_dumps(data: Any) -> str:

modify_with_jsonpath

Search in a dicitonary and replace data with jsonpath_ng

def modify_with_jsonpath(data: dict[Any, Any], path: str, new_value: Any) -> dict[Any, Any]:

Example:

from corelibs_json.json_support import modify_with_jsonpath

data = {
    'bar': {
        'a': 1,
        'b': 'c'
    },
}
print(f"OUT: {modify_with_jsonpath(__data, 'bar.a', 42)}")

Output form above will be:

{
    'bar': {
        'a': 42,
        'b': 'c'
    },
}

Development

UV setup

uv must be installed

Python venv setup

After clone, run the command below to install all dependenciss

uv sync

Build and Publish

uv build
uv publish --index opj-pypi --token <gitea token>

Python tests

All python tests are the tests/ folder. They are structured by the source folder layout

run them with

uv run pytest

Get a coverate report

uv run pytest --cov=<project>
uv run pytest --cov=<project> --cov-report=term-missing

Other tests

In the test-run folder usage and run tests are located, runt them below

uv run test-run/<script>

Requirements

Requires Python: >=3.13
Details
PyPI
2026-02-03 15:16:31 +09:00
0
Clemens Schwaighofer
7.1 KiB
Assets (2)
Versions (6) View all
2.0.3 2026-03-18
2.0.2 2026-03-13
2.0.1 2026-03-12
2.0.0 2026-03-12
1.0.1 2026-02-03