1. json(3)
  2. json(3)

NAME

json - JSON manipulation

SYNOPSIS

An experimental module for parsing and stringifying JSON data.

DESCRIPTION

The json(3) module adds methods for parsing and creating JSON documents.

USAGE

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;

BUGS

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

SEE ALSO

strike(7)

  1. January 2013
  2. json(3)