json-procs.tcl

Typed JSON export of XoWiki pages. Mapping rules:

  • Export all attributes except transient attributes prefixed with "__".
  • Determine scalar types from inherited slot metadata; use explicit mappings for otherwise untyped built-in IDs and rendering flags.
  • Export instance_attributes as an object, using form-field metadata to determine each stored value's type.
  • Export numeric fields as numbers and boolean fields as true/false. Empty numeric and boolean values become null; empty text remains "".
  • Preserve unknown types and invalid nonempty scalar values as strings. Numeric fields with keep_string_rep retain nonempty strings.
  • Export multiple-value fields as arrays of strings.
  • Export compound fields recursively as objects, removing the containing field's name prefix from component keys.
  • Export repeated fields recursively as arrays in numeric occurrence order, omitting the occurrence-zero template. Repeated compound fields therefore become arrays of objects.
  • Export stored values without applying form defaults. Preserve stored attributes no longer declared in the form; omit absent attributes.
Encode using ns_json, guarded by acs::icanuse. The web method returns pretty-printed JSON and requires site-wide administrator privileges.
Location:
packages/xowiki/tcl/json-procs.tcl
Created:
2026-10-22
Author:
Gustaf Neumann

Procedures in this file

Detailed information

xowiki::json_scalar (private)

 xowiki::json_scalar type value

Return an ns_json type/payload pair. Empty typed scalars become null; invalid nonempty legacy values remain strings.

Parameters:
type (required)
Requested JSON scalar type: number, boolean, or string.
value (required)
Stored scalar value, without applying form defaults.
Returns:
Two-element list containing the ns_json type and payload.

Partial Call Graph (max 5 caller/called nodes):
Class ::xowiki::formfield::numeric Class ::xowiki::formfield::numeric (public) xowiki::json_scalar xowiki::json_scalar Class ::xowiki::formfield::numeric->xowiki::json_scalar Class ::xowiki::formfield::range Class ::xowiki::formfield::range (public) Class ::xowiki::formfield::range->xowiki::json_scalar xowiki::Page instproc json_data xowiki::Page instproc json_data (public) xowiki::Page instproc json_data->xowiki::json_scalar xowiki::formfield::boolean instproc json_value xowiki::formfield::boolean instproc json_value (public) xowiki::formfield::boolean instproc json_value->xowiki::json_scalar xowiki::formfield::boolean_checkbox instproc json_value xowiki::formfield::boolean_checkbox instproc json_value (public) xowiki::formfield::boolean_checkbox instproc json_value->xowiki::json_scalar

Testcases:
No testcase defined.
[ show source ]