1 namespace eval ten::json {
3 namespace eval deparse {
6 list "\"" "\\\"" / \\/ \\ \\\\ \b \\b \f \\f \n \\n \r \\r \t \\t
16 variable indentBy [ expr $indentBy + $indentIncr ]
17 variable indent [ string repeat " " $indentBy ]
22 variable indentBy [ expr $indentBy - $indentIncr ]
23 variable indent [ string repeat " " $indentBy ]
28 return \"[ string map $quotes $str ]\"
40 foreach el [lrange $args 0 end] {
42 append out [ eval $el ],
45 append out $nl$indent\]
54 dict for {k v} $args {
55 append out $nl$indent[ str $k ]:\ [ eval $v ],
58 append out $nl$indent\}
62 switch -regexp [lindex $args 0] {
64 default { error "Invalid JSON type [lindex $args 0]" }
70 proc deparse_json {data {indentIncr 2}} {
71 set deparse::indentBy 0
72 set deparse::indentIncr $indentIncr
73 if [expr $indentIncr == 0] {
78 namespace inscope deparse eval $data
82 puts [ ten::json::deparse_json {
83 list {str foo} {num 0} {obj __remote_object__ {str 512}}