JSNT
A JS-based web framework that gives you easy access to json data
A JS-based web framework that gives you easy access to json data
Lets begin to code
<script type="text/javascript" src="https://cdn.yurba.one/static/jsnt/1.1/jsnt.min.js">
Here are all the basic functions you need to know if you use jsnt
Function
Outdated method
Note
get
Allows you to conveniently retrieve data from a file on the Internet or on a user's computer. With this function you can easily interact with other functions because you get a JSON object. Further, you probably won't be able to interact with JSON in file format
jsnt.get(url/file, (callback) => {
console.log(callback.data)
});
download
Allows you to download files or create new ones with content already installed
jsnt.download(file, newContent);
More: If the second argument is empty, the existing file will be selected from the path specified in the first argument
replace
Changes the information in the file and outputs a completely rewritten file
(async () => {
try {
const newContent = await jsnt.replace(url/file, someData, newData);
console.log(newContent);
} catch (error) {
console.log(error);
}
})();
remove
Deletes a column from json
jsnt.get(fileName, function(data) {
console.log(jsnt.remove(data, "someString"))
})
set
Sets a value in the structure
jsnt.set(jsonData, "person.nickname", "John2024")
The function does not create a new value if you use it in a variable. It immediately "recreates" JSON, which is specified in the first argument
has
Checks if there is a value in the structure
jsnt.has(jsonData, "person.nickname", "John2024")
filter
Filters and finds matching values
jsnt.filter(jsonData, (value) => value.age > 30);
sort
Sort JSON data by a certain key
jsnt.sort(jsonData, "age")
merge
Binds two JSON objects into one
jsnt.merge(jsonData1, jsonData2)
flatten
Converting a nested JSON structure into a flat structure
jsnt.flatten(jsonData)
If you don't understand what the function will return, it will make {"data": {"name": "UserName"}} it will do {"data.name": "UserName"}
validate
Checking the json structure for correct syntax
jsnt.validate(jsonData)
count
Counts the number of keys in JSON
jsnt.count(jsonData)
keys
Outputs all the keys that are in the JSON structure
jsnt.keys(jsonData)
isEmpty
Checks if the key in JSON is empty
jsnt.isEmpty(jsonData[key])
toString
Converts JSON structure to string
jsnt.toString(jsonData)
toArray
Turns JSON object into an array
jsnt.toArray(jsonData)
toJson
Turns a string into a JSON object
jsnt.toJson(jsonData)
sum
Sums all numbers in JSON
jsnt.sum(jsonData, "age")
equal
Checks if 2 JSONs are equivalent
jsnt.equal(jsonData, jsonData2)
group
Grouping JSON data by a certain key
jsnt.group(jsonData, "age")
renameKey
Changes the key in JSON
jsnt.renameKey(jsonData, "age", "fullAge")
average
Calculates the average value from the sum that is obtained by adding all int lines in JSON
jsnt.average(jsonData, "age")
map
Allows to execute the function for each JSON object
jsnt.map(jsonData, item => item.toUpperCase())
date.convert
Convert JSON object containing unix date to regular date
jsnt.date.convert(unixTime, "DD.MM.YYYY hh:mm:ss", "Europe/Kiev")
The second and third argument is the format and timezone. You can specify any format you want, which would, for example, display only the year or only the hours.
date.diff
Calculates the difference between 2 unix dates in JSON. Outputs the results as multiple units: how many years or months have passed
jsnt.date.diff(unixTime, unixTime2, units)
Argument units are what you want to bring out separately. If the argument is not specified (empty, undefined), then the full list is output as a json
date.now
Returns current UNIX timestamp in seconds
jsnt.date.now()
date.add
Adds the time to the UNIX date
jsnt.date.add(unixTime, {years: 1})
Available time units that can be used: years, months, days, hours, minutes, seconds
date.substr
Takes time away from the UNIX date
jsnt.date.substr(unixTime, {days: 1})
Available time units that can be used: years, months, days, hours, minutes, seconds
cache.new
Creates a new data cache
jsnt.cache.new("cacheKeyName", jsonValue)
cache.add
Adds json data to the existing cache
jsnt.cache.add("cacheKeyName", jsonValue)
cache.get
Gets the value of the cache
jsnt.cache.get("cacheKeyName")
cache.remove
Deletes the key from the cache
jsnt.cache.remove("cacheKeyName")
cache.clear
Deletes the entire cache
jsnt.cache.clear("cacheKeyName")
parseYAML
Turns YAML into JSON
jsnt.parseYAML(yamlString)
toYAML
Converts JSON to YAML
jsnt.toYAML(yamlString)
parseXML
Converts XML to JSON
jsnt.parseXML(xmlString)
toXML
Turns JSON into XML
jsnt.toXML(xmlString)