Library › json — JSON
json — JSON
import json
Turn JSON text into Turtle values, and Turtle values back into JSON text, for web APIs and saved data.
Functions
load, json_text, json_read, json_write, json_get.
load[text]
Reads JSON text.
Example
import json
user = load['{"name": "Ann"}']
show user .
Output
{ "name": "Ann" }
json_text[value]
Writes a value as JSON, on one line.
Example
show json_text[map ["id": 7, "tags": list ["a", "b"]]] .
Output
{"id":7,"tags":["a","b"]}
json_read[path]
Reads a JSON file.
Example
json_write["user.json", map ["name": "Ann"]]
show json_read["user.json"] .
Output
{ "name": "Ann" }
json_write[path, value]
Saves a value to a file as indented JSON.
Example
json_write["out.json", list [1, 2]]
show json_read["out.json"] .
Output
[ 1, 2 ]
json_get[value, step, step, ...]
Follows a path of map keys and list positions into a value.
Example
config = load['{"server": {"port": 8080}}']
port = json_get[config, "server", "port"]
show port .
Output
8080Top
Turtle