indent_one
foreach el [lrange $args 0 end] {
append out $nl$indent
- append out [ eval $el ],
+ append out [ deparse $el ],
}
outdent_one
append out $nl$indent\]
set out \{
indent_one
dict for {k v} $args {
- append out $nl$indent[ str $k ]:\ [ eval $v ],
+ append out $nl$indent[ str $k ]:\ [ deparse $v ],
}
outdent_one
append out $nl$indent\}
}
- proc deparse {args} {
- switch -regexp [lindex $args 0] {
- ^num|str|obj|list$ -
- default { error "Invalid JSON type [lindex $args 0]" }
+ proc deparse {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 $args ]
+ return [ eval $data ]
}
}
}
puts [ ten::json::deparse_json {
- list {str foo} {num 0} {obj __remote_object__ {str 512}}
-} 0 ]
+ list {str foo} {num 0} {obj __remote_object__ {str 512}} {null}
+} 2 ]