load-json-file

  • Version 7.0.1
  • Published
  • 5.37 kB
  • No dependencies
  • MIT license

Install

npm i load-json-file
yarn add load-json-file
pnpm add load-json-file

Overview

Read and parse a JSON file

Index

Functions

function loadJsonFile

loadJsonFile: <ReturnValueType = JsonValue>(
filePath: string,
options?: Options
) => Promise<ReturnValueType>;
  • Read and parse a JSON file.

    It also strips UTF-8 BOM.

    Example 1

    import {loadJsonFile} from 'load-json-file';
    const json = await loadJsonFile('foo.json');
    //=> {foo: true}

function loadJsonFileSync

loadJsonFileSync: <ReturnValueType = JsonValue>(
filePath: string,
options?: Options
) => ReturnValueType;
  • Read and parse a JSON file.

    It also strips UTF-8 BOM.

    Example 1

    import {loadJsonFileSync} from 'load-json-file';
    const json = loadJsonFileSync('foo.json');
    //=> {foo: true}

Interfaces

interface Options

interface Options {}

    property beforeParse

    readonly beforeParse?: BeforeParse;
    • Applies a function to the JSON string before parsing.

    property reviver

    readonly reviver?: Reviver;
    • Prescribes how the value originally produced by parsing is transformed, before being returned. See the [JSON.parse docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter) for more.

    Type Aliases

    type BeforeParse

    type BeforeParse = (data: string) => string;

      type JsonValue

      type JsonValue =
      | string
      | number
      | boolean
      | null
      | { [Key in string]?: JsonValue }
      | JsonValue[];

        type Reviver

        type Reviver = (this: unknown, key: string, value: unknown) => unknown;

          Package Files (1)

          Dependencies (0)

          No dependencies.

          Dev Dependencies (3)

          Peer Dependencies (0)

          No peer dependencies.

          Badge

          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/load-json-file.

          • Markdown
            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/load-json-file)
          • HTML
            <a href="https://www.jsdocs.io/package/load-json-file"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>