} else {
set deparse::nl "\n"
}
- namespace inscope deparse eval $data
+ deparse::deparse $data
+ }
+
+ namespace eval tclify {
+
+ proc str {str} { return $str }
+
+ proc num {num} { return $num }
+
+ proc obj {args} {
+ return $args
+ }
+
+ proc tclify {data} {
+ switch -regexp [lindex $data 0] {
+ ^true|false|null$ { uplevel 1 return [lindex $data 0] }
+ ^num|str|obj|list$ {}
+ default { error [ concat "Invalid JSON type " [lindex $data 0 0] ] }
+ }
+ return [ eval $data ]
+ }
+ }
+
+ proc tclify_json {data} {
+ tclify::tclify $data
}
}
-puts [ ten::json::deparse_json {
- list {str foo} {num 0} {obj __remote_object__ {str 512}} {null}
-} 2 ]
+set ex_json { list {str foo} {num 0} {obj __remote_object__ {str 512}} {null} }
+
+puts [ ten::json::deparse_json $ex_json 2 ]
+
+dict for {k v} [ ten::json::tclify_json [
+ lindex [ ten::json::tclify_json $ex_json ] 2
+] ] { puts "$k: $v" }