Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→edit-package-jsonnext

edit-package-json0.10.1

Edit package.json without parsing, as string, to keep the formatting intact

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — SET()
  • API — DEL()
  • API — VERSION
  • API — TYPES
  • Changelog

Installation

Quick Take

Examples

  • Delete an array item by its dot-path index
  • Delete a nested object key
  • Minimal example, del()
  • Minimal example, set()
  • Replace an existing array item by its dot-path index
  • Replace an existing nested value with null
  • Set a numeric value without changing surrounding formatting
  • Replace an object value while preserving outer formatting

Purpose

Edit JSON contents as strings to guarantee the formatting will be intact.

API uses object-path notation to set values on any (for now, only already-existing) paths in JSON.

It’s powering the update-versions CLI.

API — set()

The function set() is imported like this:

It’s a function which takes three input arguments:

Input argumentTypeObligatoryDescription
str
Type: String
Obligatory: yes
strStringyesJSON file contents
path
Type: String
Obligatory: yes
pathStringyesDesired EXISTING path in the object, must follow object-path notation
valToInsert
Type: Whatever
Obligatory: yes
valToInsertWhateveryesWhat to insert at the given path

You can’t create new paths, only amend existing-ones.

Function returns an amended string.

API — del()

The function del() is imported like this:

It’s a function which takes two input arguments:

Input argumentTypeObligatoryDescription
str
Type: String
Obligatory: yes
strStringyesJSON file contents
path
Type: String
Obligatory: yes
pathStringyesDesired path in the object to delete, must follow object-path notation

Function returns an amended string.

API — version

You can import version:

API — types

This package is written in TypeScript and exports the type Inputs — the internal request shape both set() and del() build — the source str, the path, the mode and, for set(), the valToInsert.

import type { Inputs } from "edit-package-json";

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab