Function removeObject

  • Parameters

    • filePath: string

      The path to the JSON file.

    • id: string | number

      The ID of the object to be removed.

    Returns Promise<void>

    • A promise that resolves when the object is successfully removed.

    Throws

    • If there is an error while removing the object.

    • Check if the JSON file exists using the exist function.

    • If the file does not exist, log an error message and exit the process.

    • Load the JSON file using the readJson function.

    • Filter the loaded JSON content to create a new array without the item with the matching ID.

    • Write the updated content back to the JSON file using the writeJson function.

    Example

    await removeObject("data.json", 123);
    

Generated using TypeDoc