JSON

6 functions for parsing, generating, querying, and persisting JSON data. Works with REST APIs, config files, and structured biological databases.

json_parse

Parse a JSON string into a BioLang value (map, list, string, number, bool, or nil).

json_parse(s) -> value
let data = json_parse('{"gene": "BRCA1", "variants": [1, 2, 3]}')
println(data.gene)       # "BRCA1"
println(data.variants)   # [1, 2, 3]

json_stringify / json_pretty

Serialize a value to a JSON string. json_pretty adds indentation.

json_stringify(value) -> string
json_pretty(value) -> string
let result = {"gene": "BRCA1", "pvalue": 0.001, "significant": true}
json_stringify(result)
# '{"gene":"BRCA1","pvalue":0.001,"significant":true}'

json_pretty(result)
# '{
#   "gene": "BRCA1",
#   "pvalue": 0.001,
#   "significant": true
# }'

read_json / write_json

Read/write JSON from/to files.

read_json(path) -> value
write_json(value, path) -> string
let config = read_json("pipeline_config.json")
println("Threads:", config.threads)

let results = {"samples": 48, "pass_qc": 45, "mean_coverage": 32.5}
write_json(results, "qc_summary.json")

json_keys

Return the list of keys from a JSON object (map).

json_keys(value) -> list
let data = json_parse('{"gene": "BRCA1", "pvalue": 0.001, "significant": true}')
json_keys(data)   # ["gene", "pvalue", "significant"]

# Inspect API response structure
let resp = http_get("https://api.example.com/gene/672")
let keys = json_keys(json_parse(resp.body))
println("Available fields:", keys)