Skip to content

advice-animal/codemod-json

Repository files navigation

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.

About

Surgical edits to JSON documents

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •