xowiki::json_scalar (private)

 xowiki::json_scalar type value

Defined in packages/xowiki/tcl/json-procs.tcl

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.
Source code:
    if {$value eq "" && $type in {number boolean}} {
      return [list null ""]
    }
    switch -- $type {
      boolean {
        switch -nocase -- $value {
          t - true - yes - on - 1 {return {boolean true}}
          f - false - no - off - 0 {return {boolean false}}
        }
      }
      number {
        # JSON numbers exclude NaN, infinity, hexadecimal and leading zeros.
        if {[regexp {^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?$} $value]} {
          return [list number $value]
        }
      }
    }
    return [list string $value]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: