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.0b1.tar.gz (13.5 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.0b1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file codemod_json-0.5.0b1.tar.gz.

File metadata

  • Download URL: codemod_json-0.5.0b1.tar.gz
  • Upload date:
  • Size: 13.5 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.0b1.tar.gz
Algorithm Hash digest
SHA256 f063b82401bb21e81c4b356a7f97ddf0b7e805571f1c3d4b405e5e098c4df2ad
MD5 4a42960b3dda1618fa947019b81a1181
BLAKE2b-256 32c0e81b9b4cc5bedf3522bf246ddc84fee1b89adf05aff7ded8b5b5e4554197

See more details on using hashes here.

Provenance

The following attestation bundles were made for codemod_json-0.5.0b1.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.0b1-py3-none-any.whl.

File metadata

  • Download URL: codemod_json-0.5.0b1-py3-none-any.whl
  • Upload date:
  • Size: 11.9 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.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 47d393e4a2c14f4de11dcd8ab72f44b9dd1c0f930ea64b9b9727ee837b28751f
MD5 c8ca03a5e9c2446dfb28ae10fec2f8fd
BLAKE2b-256 ff0f1465297f7c689c855c199817681a1ff6ab26d640e3b273c429ed900bbd89

See more details on using hashes here.

Provenance

The following attestation bundles were made for codemod_json-0.5.0b1-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