util::tdomNodes2dict (private)

 util::tdomNodes2dict nodes parentType

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

Helper proc for util::json2dict, which returns the tDOM structure in the form of a Tcl dict. Use this proc only on dom structures created with "porse -json", since it depends on the internal node structure of tDOM. It would be certainly better to have this function built-in in tDOM (call like "asDict", similar to "asXML")

Parameters:
nodes
parentType
Returns:
dict
Author:
Gustaf Neumann

Partial Call Graph (max 5 caller/called nodes):
%3 test_json_to_dict json_to_dict (test acs-tcl) util::tdomNodes2dict util::tdomNodes2dict test_json_to_dict->util::tdomNodes2dict util::tdomDoc2dict util::tdomDoc2dict (public) util::tdomDoc2dict->util::tdomNodes2dict

Testcases:
json_to_dict
Source code:
    set result ""
    foreach n $nodes {
        set children [$n childNodes]
        set jsonType [$n jsonType]
        set childrendValue [util::tdomNodes2dict $children $jsonType]

        switch $jsonType {
            OBJECT {
                if {[$n nodeName] ne "objectcontainer" || $parentType eq "OBJECT"} {
                    lappend result [$n nodeName]
                }
                lappend result $childrendValue
            }
            NONE {
                lappend result [$n nodeName] $childrendValue
            }
            ARRAY {
               if {[$n nodeName] ne "arraycontainer" || $parentType eq "OBJECT"} {
                   lappend result [$n nodeName]
               }
                lappend result $childrendValue
            }
            default {
                set op [expr {[llength $nodes] > 1 ? "lappend" : "set"} ]
                $op result [$n nodeValue]
            }
        }
    }
    return $result
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: