Skip to main content

Lib to modify json inplace

Project description

codemod-json

This library makes surgical edits to JSON documents, based on tree-sitter and inspired by tomlkit and pyupgrade. Preserves all whitespace and formatting on lines that don't require changes, and generally within a line as well, so you can make minimal diffs in your codemod tools.

Basic Usage

{
    // some comment
    "version": ["foo"],
    "commands": [], // another comment
}
from codemod_json import parse
stream = parse(somepath.read_bytes())
if stream["version"] == ["2.7"]:
    stream["version"][:] = ["3.6", "3.13"]
somepath.write_bytes(stream.text)
{
    // some comment
    "version": ["3.6", "3.13"],
    "commands": [], // another comment
}

Version Compat

Usage of this library should work back to 3.9 (because of the tree-sitter dep), but development (and mypy compatibility) only on 3.10-3.12. Linting requires 3.12+ for full fidelity.

Versioning

This library follows meanver which basically means semver along with a promise to rename when the major version changes.

License

codemod-json is copyright Tim Hatch, and licensed under the MIT license. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codemod_json-0.5.1.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codemod_json-0.5.1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file codemod_json-0.5.1.tar.gz.

File metadata

  • Download URL: codemod_json-0.5.1.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for codemod_json-0.5.1.tar.gz
Algorithm Hash digest
SHA256 c65ec3e4deb55c73a0c68f99a9625597c57a688b71aba03ca97f35c61469ed3b
MD5 73cad8ae12e73f91359e29cc35924810
BLAKE2b-256 07533d2ee6d101401278a197d3535236eabd1d24106c2f447ef927b111c7c794

See more details on using hashes here.

Provenance

The following attestation bundles were made for codemod_json-0.5.1.tar.gz:

Publisher: build.yml on advice-animal/codemod-json

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codemod_json-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: codemod_json-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for codemod_json-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97cbadf235a445c80c8687f9f4f3a4da584073620c2bc1394514795ff9b25e9d
MD5 cca37a6007b9433a735d3611e68f3bd6
BLAKE2b-256 d4cd1151c59d8bd573ad8ffd80e6141d6081e6c3f2ab541650a11224df43cb69

See more details on using hashes here.

Provenance

The following attestation bundles were made for codemod_json-0.5.1-py3-none-any.whl:

Publisher: build.yml on advice-animal/codemod-json

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page