json - JSON manipulation
An experimental module for parsing and stringifying JSON data.
The json(3) module adds methods for parsing and creating JSON documents.
Parsing JSON data can be from a file, string or variable. After parsing the JSON data the parsed data is available on the global json_doc associative array. Use the json.print method to quickly inspect the contents of the parsed data.
require 'json';
# parse a json document
json.parse < "${process_dirs[root]}/package.json";
json.print;
# parse a json string
json.parse <<< '{ "data": "value" }';
json.print;
# clean up parsed json data
json.clean;
Converting to JSON is achieved using references to variable names and afterwards the JSON string is available in the global json_str variable. Use the json.string method to print the JSON string data.
require 'json';
toJSON() {
declare -A doc;
doc[key]="value";
doc[greeting]="hello world";
# doc is the *name* of the variable to stringify
json.stringify <<< "doc";
# print the result
json.string;
}
toJSON;
json is written in bash and depends upon bash >= 4.
The json(3) module is derived from json-sh(1).
json is copyright (c) 2012 muji http://xpm.io