Ciql-JSON is a tool for manipulating JSON files. it allows to open and modify a JSON file and save results in another file or in the current file. You can also use it to create JSON files, it is very practical and easy to use.
yarn add ciql-json
npm i ciql-json
const ciqlJSON = require('ciql-json')
you use the open
method to open an existing JSON file. Once the file is linked you have access to the modification methods.
const ciqlJson = require("ciql-json")
ciqlJson
.open("file.json")
.set("address", {town : "", city : ""})
.save()
NB : If you do not specify an output file in the save
function, the change will be made in the input file.
Use the create
methode to initialize a JSON object.
const ciqlJson = require("ciql-json")
ciqlJson
.create({name:"Edy"})
.set("address", {town : "Abidjan", city : "Marcory"})
.save("me.json")
//output file (me.json): {name:"Edy", address : {town : "Abidjan", city : "Marcory"}
NB : In this case, If you do not specify an output file, there is an error because there, not input file.
Use the save
method to save the JSON data in current file or other file.
const ciqlJson = require("ciql-json")
ciqlJson
.create({name : "Edy", school : "ESATIC"})
.save("data.json")
//output file (data.json): {name:"Edy", school : "ESATIC"}
Use the set
method to add or modify the values of the JSON object.
const ciqlJson = require("ciql-json")
ciqlJson
.create({})
.set("school", "ESATIC")
.set("location", "Treichville")
.set("address", "")
.save('data.json')
//output file (data.json): {school : "ESATIC", location : "Treichville", address : ""}
You can modify an object by specifying the key :
const ciqlJson = require("ciql-json")
ciqlJson
.create({school : {name : "ESATIC"}})
.set("school.location", "Treichville")
.save('data.json')
//output file (data.json): {school : {name : "ESATIC", location: "Treichville",}}
Use the remove
method to delete key in JSON data.
const ciqlJson = require("ciql-json")
ciqlJson
.create({})
.set("school", "ESATIC")
.set("location", "Treichville")
.remove("school")
.save('data.json')
//output file (data.json): { location : "Treichville"}
Extract a schema in the JSON object following the destructuring of ES6.
const ciqlJson = require("ciql-json")
ciqlJson
.create({name:"KOFFI", school : "ESATIC", address : "Abidjan"})
.extract("{ school }")
.save('data.json')
//output file (data.json): {school : "ESATIC"}
Add data to an array value.
const ciqlJson = require("ciql-json")
ciqlJson
.create({school : "ESATIC", courses : []})
.pushTo("courses","Data Sciences", "MERISE")
.save('data.json')
//output file (data.json): {school : "ESATIC", courses : ["Data Sciences", "MERISE"]}
Delete last data to an array value.
const ciqlJson = require("ciql-json")
ciqlJson
.create({school : "ESATIC", courses : []})
.pushTo("courses","Data Sciences", "MERISE")
.popTo("courses")
.save('data.json')
//output file (data.json): {school : "ESATIC", courses : ["Data Sciences"]}
Use getData
if you want to return the final value of the json in a variable.
const ciqlJson = require("ciql-json")
const data = ciqlJson
.create({})
.set("school", "ESATIC")
.set("location", "Treichville")
.getData()
//output : data = {school : "ESATIC", location : "Treichville"}
getKeys
return keys of the json Object.
const ciqlJson = require("ciql-json")
const data = ciqlJson
.create({})
.set("school", "ESATIC")
.set("location", "Treichville")
.getKeys()
//output : data = ["school", "location" ]
getValues
return values of the json Object.
const ciqlJson = require("ciql-json")
const data = ciqlJson
.create({})
.set("school", "ESATIC")
.set("location", "Treichville")
.getValues()
//output : data = ["ESATIC", "Treichville" ]
MIT License
Copyright (c) 2021 dykoffi
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
LICENSE MIT