json

Read and write JSON, the data format of the web and of most security tools.

import json

Example

import json

let alert = {"rule": "Brute force", "ip": "203.0.113.42", "count": 22}
let text = json.stringify(alert)
say(text)

let back = json.parse(text)
say(back.ip, back["count"] + 1)
say(json.stringify({"tags": ["ssh", "auth"]}, true))

Functions

parse(text)

returns value

Turn JSON text into TB values (objects become maps, arrays become lists).

stringify(value, pretty?)

returns text

Turn a TB value into JSON text. Pass true for pretty, indented output.

read(path)

returns value

Read a .json file into TB values.

write(path, value, pretty?)

Save a TB value as a .json file (pretty and indented unless pretty is false).