项目作者: tiaanduplessis

项目描述 :
Read or write to a JSON file synchronously
高级语言: JavaScript
项目地址: git://github.com/tiaanduplessis/json-reader-writer.git
创建时间: 2017-01-29T18:05:06Z
项目社区:https://github.com/tiaanduplessis/json-reader-writer

开源协议:MIT License

下载


📘 json-reader-writer ✍️


Read or write to a JSON file synchronously




Table of Contents


Table of Contents
  • Install

  • Usage

  • API

  • Contribute

  • License

  • Install

    Note that this module Uses JSON.stringify, which can run out of memory. If the data you need to write is large, consider using a streaming JSON writer, such as @mbostock’s json-write. Otherwise, go ahead and…

    1. $ npm install --save json-reader-writer
    1. $ yarn add json-reader-writer

    Usage

    1. const {readJSON, writeJson} = require('json-reader-writer')
    2. const filePath = 'foo.json'
    3. const obj = {
    4. foo: 1,
    5. bar: 2,
    6. baz: 2
    7. }
    8. console.log(writeJson(filePath, obj)) // true if successful
    9. console.log(readJSON(filePath)) // { foo: 1, bar: 2, baz: 2 }

    API

    readJSON(filename)

    Takes the filename of the JSON file you want to read from as argument. Defaults to file.json if no filename provided.

    writeJSON(filename, objectToWrite)

    Takes the filename of the JSON file you want to write to and the valid object you want to write as arguments.

    Contribute

    Contributions are welcome. Please open up an issue or create PR if you would like to help out.

    Note: If editing the README, please conform to the standard-readme specification.

    License

    Licensed under the MIT License.