1.0.2 • Published 7 years ago

interractjson v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
7 years ago

InterractJSON

This NodeJS module will allow you to use files with JSON extensions as storage. You will be able to have a better interplay between JavaScript and JSON.

This module is to use in case you need to simplify the relation between your Javascript code and a JSON file. Do you want to read ? Insert data into a JSON file ?

So let's go !

My npm account is here

How to install

In the first time, you will have to add the module in your project. For this fact :

cd /your_project/node_modules
npm install interractjson

For using this module, you should install fs module Normally, the download of fs module will be done automatically but you never know !

cd /your_project/node_modules
npm install fs

This module has 2 functions (reading and writing) :

ReadJSON(path)
WriteJSON(path, input)
ParameterUsing
pathacces path to your file.
inputthe code, text you want to insert in the JSON file.

Exemple

If you want to write into your JSON, you can use :

const IJ = require('interractjson')

let input = {"username": "Freeze", "langage":["Javascript","C#", "HTML/CSS","PHP", "MYSQL", "Ruby", "Ruby on Rails"]}
IJ.WriteJSON("src/file.json", input)

The code will insert in your JSON file :

{
  "username": "Freeze",
  "langage": [
    "Javascript",
    "C#",
    "HTML/CSS",
    "PHP",
    "MYSQL",
    "Ruby",
    "Ruby on Rails"
  ]
}

If you want to recover a data from your JSON file :

const IJ = require('interractjson')

let read = IJ.ReadJSON("src/file.json")
console.log(read)

This code will return you an object. To select a specific data, consider that the read function is your JSON object. As a result, you only need to specify the data you want to recover :

const IJ = require('interractjson')

let read = IJ.ReadJSON("src/file.json")
console.log(read.username)  // Returns the following data : "Freeze"
console.log(read.langage[1]) // Returns the following data: "C#"

Finally, if you want to update your JSON file by keeping some values :

const IJ = require('interractjson')

IJ.WriteJSON("test.json", {"username": readJSON("test.json").username, "langage":["Javascript","C#", "HTML/CSS","PHP", "MYSQL", "Ruby", "Ruby on Rails"]})

Thank you for taking the time to read this micro project ! :)

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago