--json (or -j) selects JSON output. The parser still walks the input and populates the object registry exactly as for HTML, but instead of emitting markup it writes a single JSON document describing every registered object plus a flat list of every resolved cross-reference. The output is the contract for downstream tooling.
sql2html --json < schema.sql > schema.json dbschema -d mydb -ss | sql2html --json -h "mydb" -2 > mydb.json
{
"sql2html_version": "<semver>",
"generated_at": "<ISO-8601 UTC>",
"source": {
"title": "<value of -h, or null>",
"dbname": "<-d default, or null>",
"dbserver": "<-i default, or null>",
"owner": "<-o default, or null>",
"line_count": <int>
},
"objects": [ ... ],
"references": [ ... ]
}
One record per registered object. Every record carries a type-specific attributes block plus a small envelope:
{
"type": "table" | "view" | "synonym" | "index" |
"trigger" | "routine" | "aggregate" | "udt" |
"constraint",
"name": "<identifier>",
"qualified_name": { "dbserver": ..., "dbname": ..., "owner": ..., "object": ... },
"anchor": "{type}_{name}[_{line}]",
"source": { "line": <int>, "column": <int>, "byte_offset": <int> },
"attributes": { ... }
}
The anchor field is identical to the HTML/PDF anchor for that object, so a JSON-driven tool can emit links into the HTML or PDF output without re-deriving the scheme.
| Type | Notable attributes |
|---|---|
| table | columns (with datatype, not_null, default, check), primary_key, unique, foreign_keys (with references back-pointer), checks, fragmentation, lock_mode, extent_size, next_size, in_dbspace, is_temp. |
| view | definition_sql, with_check_option, referenced_tables. |
| index | on_table, unique, cluster, distinct, columns, access_method, fill_factor, fragmentation. |
| trigger | on_table, events, update_columns, when_clause, plus per-clause action lists for before / for_each_row / after. |
| routine | kind (procedure / function), params, returns, language, body_sql, and a calls[] list that resolves udr / uda targets. |
| udt | Base type for opaque / row / distinct types, with the captured body verbatim. |
| synonym | target as { name, anchor }. |
| constraint | Back-pointer to the table it belongs to. |
Independent of the per-object detail, every resolved cross-reference is also emitted as a flat list, so consumers can build a call graph or dependency diagram without re-parsing:
{
"from": { "type": ..., "name": ..., "anchor": ... },
"to": { "type": ..., "name": ..., "anchor": ... },
"kind": "column_type" | "fk_target" | "trigger_target" |
"view_source" | "execute_procedure" | "synonym_target",
"source_line": <int>
}
| Guarantee | Detail |
|---|---|
| Field naming | Field names follow snake_case. |
| Optional fields | Emitted as null rather than omitted, so consumers can rely on fixed shapes. |
| Versioning | sql2html_version at the top is a semver string; the schema is versioned alongside the binary. |
| Anchor parity | Anchor strings match the HTML and PDF outputs verbatim — one tool's links work against another tool's documents. |
--json ignores the effects of -h, -t, and -s on the output shape (the object list is the structured equivalent of the HTML summary; the title is captured as source.title). Two-pass mode (-2) is still honoured for reference resolution — it determines which forward references appear in references[].
To discuss how Oninit ® can assist please call on +1-913-732-8892 or alternatively just send an email specifying your requirements.
You get all this for free.. think about what you get if you pay us