doctools:...port::json(3tcl)
β¨ NAME β¨
doctools::idx::export::json β the JSON export plugin, bestie π
(it lives in the 3tcl manual section, iykyk)
πΈ SYNOPSIS πΈ
package require Tcl 8.5 9
package require doctools::idx::export::json ?0.2?
package require textutil::adjust
export serial configuration
π¦ DESCRIPTION π¦
Okay so, this package is the doctools keyword index export plugin that handles the whole "make it JSON" thing. That's its entire job. It ate and left no crumbs β¨
It's an internal package of doctools, fr fr. It exists to be used by the higher-level management packages that deal with keyword indices β especially doctools::idx::export, the export manager. It's the backstage crew, not the main character.
Can you use it straight from a regular interpreter? Technically yes but only with contortions π and it is not recommended. The proper way β the slay way β is through the package doctools::idx::export and the export manager objects it provides. Periodt.
π API π
The API this package gives you satisfies the spec of the docidx export plugin API version 2. No cap.
export serial configurationβ this command takes the canonical serialization of a keyword index (as specified down in the Keyword index serialization format section, and contained inserial), plus theconfiguration, a dictionary, and it generates JSON markup encoding the index. The created string gets returned as the result of the command. That's it, that's the whole vibe π
π JSON NOTATION OF KEYWORD INDICES π
The JSON format used for keyword indices is a direct translation of the Keyword index serialization format β it maps Tcl dictionaries as JSON objects and Tcl lists as JSON arrays. So clean, so simple, obsessed.
For example, this Tcl serialization:
doctools::idx {
label {Keyword Index}
keywords {
changelog {changelog.man cvs.man}
conversion {doctools.man docidx.man doctoc.man apps/dtplite.man mpexpand.man}
cvs cvs.man
}
references {
apps/dtplite.man {manpage dtplite}
changelog.man {manpage doctools::changelog}
cvs.man {manpage doctools::cvs}
docidx.man {manpage doctools::idx}
doctoc.man {manpage doctools::toc}
doctools.man {manpage doctools}
mpexpand.man {manpage mpexpand}
}
title {}
}
is equivalent to this JSON string π«Ά:
{
"doctools::idx" : {
"label" : "Keyword Index",
"keywords" : {
"changelog" : ["changelog.man","cvs.man"],
"conversion" : ["doctools.man","docidx.man","doctoc.man","apps\/dtplite.man","mpexpand.man"],
"cvs" : ["cvs.man"],
},
"references" : {
"apps\/dtplite.man" : ["manpage","dtplite"],
"changelog.man" : ["manpage","doctools::changelog"],
"cvs.man" : ["manpage","doctools::cvs"],
"docidx.man" : ["manpage","doctools::idx"],
"doctoc.man" : ["manpage","doctools::toc"],
"doctools.man" : ["manpage","doctools"],
"mpexpand.man" : ["manpage","mpexpand"]
},
"title" : ""
}
}
π CONFIGURATION π
The JSON export plugin recognizes these configuration variables and switches up its behaviour according to what they say:
boolean indentedβ if this flag is set, the plugin breaks the generated JSON code across lines and indents it according to its inner structure, with each key of a dictionary on a separate line. If the flag is not set (that's the default, bestie), the whole JSON object is written on a single line, with minimum spacing between all elements. Compact queen πboolean alignedβ if this flag is set, the generator makes sure the values for the keys in a dictionary are vertically aligned with each other, for a nice little table effect. To make that work, this also implies thatindentedis set. If the flag is not set (again, the default), the output is formatted per the value ofindented, without any attempt to align the values for dictionary keys.
Heads up: this plugin ignores the standard configuration variablesuser,format,file, andmap, along with their values. Not its business, not its problem π
π§ KEYWORD INDEX SERIALIZATION FORMAT π§
Okay so here's where we specify the format the doctools v2 packages use to serialize keyword indices as immutable values for transport, comparison, etc. Very demure, very mindful.
We distinguish between regular and canonical serializations. A keyword index may have more than one regular serialization, but only exactly one of them will be canonical. Iconic.
regular serialization
- An index serialization is a nested Tcl dictionary.
- This dictionary holds a single key,
doctools::idx, and its value. This value holds the contents of the index. - The contents of the index are a Tcl dictionary holding the title of the index, a
label, and thekeywordsandreferences. The relevant keys and their values are:titleβ the value is a string containing the title of the index.labelβ the value is a string containing a label for the index.keywordsβ the value is a Tcl dictionary, using the keywords known to the index as keys. The associated values are lists containing the identifiers of the references associated with that particular keyword. Any reference identifier used in these lists has to exist as a key in thereferencesdictionary β see the next item for its definition.referencesβ the value is a Tcl dictionary, using the identifiers for the references known to the index as keys. The associated values are 2-element lists containing the type and label of the reference, in this order. Any key here has to be associated with at least one keyword, i.e. occur in at least one of the reference lists which are the values in thekeywordsdictionary β see the previous item for its definition.
- The type of a reference can be one of two values:
manpageβ the identifier of the reference is interpreted as a symbolic file name, referring to one of the documents the index was made for.urlβ the identifier of the reference is interpreted as an url, referring to some external location, like a website, etc.
canonical serialization
The canonical serialization of a keyword index has the format specified in the previous item, and then additionally satisfies the constraints below, which make it unique among all the possible serializations of the keyword index:
- The keys found in all the nested Tcl dictionaries are sorted in ascending dictionary order, as generated by Tcl's builtin command
lsort -increasing -dict. - The references listed for each keyword of the index, if any, are listed in ascending dictionary order of their labels, as generated by Tcl's builtin command
lsort -increasing -dict.
π BUGS, IDEAS, FEEDBACK π
This document, and the package it describes, will undoubtedly contain bugs and other problems. Not a vibe, but it's real. Please report such in the category doctools of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. Please also report any ideas for enhancements you may have for either the package and/or the documentation β we want all of them π«Ά
When proposing code changes, please provide unified diffs, i.e. the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. Do that, bestie π
β KEYWORDS β
JSON, doctools, export, index, serialization
π CATEGORY π
Text formatter plugin
π COPYRIGHT π
Copyright (c) 2009-2019 Andreas Kupries <andreas_kupries@users.sourceforge.net>
And that's the whole page, no crumbs left π
this one came from tcllib, version 0.2, and it's the doctools:...port::json page in the 3tcl manual section β go off, go read, go slay β¨π¦π
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2009-2019 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms