Quickly create read-write json files f2json
- Quick Import and write out the JSON data to the file
- Introduce a Json file operation in your code using a relative path
- You can use the created file as a temporary cache
npm install f2json yarn add f2json - f2json
- F2Json ⏏
- new F2Json([dirname])
- .getLastCallDirname() ⇒
String - .json2file(path, json)
- .file2json(path, encoding) ⇒
Object.<json, ok> - .clear(path_)
- F2Json ⏏
Create f2Json
| Param | Type | Description |
|---|---|---|
| [dirname] | String |
Optional,You can also pass in a relative path such as __dirname in your code file |
Example
Basic usage:
index.js :
var F2Json = require("f2json")
var f2json = new F2Json()
f2json.json2file("./cache/user.json",[
{name:"Changlon",age:22},
...
])
var {json} = f2json.file2json("./cache/user.json")
console.log(json) Returns the file path that called this function
Kind: instance method of F2Json
Writes the json object as data to the specified fileWrites the json object as data to the specified file
Kind: instance method of F2Json
| Param | Type |
|---|---|
| path | String |
| json | Object |
Read the file as a Json object in Json format
Kind: instance method of F2Json
Returns: Object.<json, ok> - returns data json and function ok
When you call the OK function, the modified data json is saved to the corresponding file
| Param | Type |
|---|---|
| path | String |
| encoding | String |
Type an empty json object into the specified file
Kind: instance method of F2Json
| Param | Type |
|---|---|
| path_ | String |
Please submit all issues and pull requests to the Changlon/f2json repository!
Run tests using npm test.
If you have any problem or suggestion please open an issue here.