Skip to content

Commit

Permalink
tabify
Browse files Browse the repository at this point in the history
  • Loading branch information
bovine committed Jun 26, 2012
1 parent 3465819 commit 1cb6988
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions yajl.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ proc yajl_atom_to_list {_yajl _index yajlLength} {

#
# json2dict - parse json and return a key-value list suitable for
# loading into a dict or an array. This is usually a friendlier
# loading into a dict or an array. This is usually a friendlier
# format to parse than the direct output of the "get" method.
# (inspired and named after the tcllib proc ::json::json2dict)
#
Expand All @@ -157,28 +157,28 @@ proc json2dict {jsonText} {
# a yajltcl object
#
proc add_array_to_json {json _array} {
upvar $_array array
upvar $_array array

$json map_open
$json map_open

foreach key [lsort [array names array]] {
$json string $key string $array($key)
}
foreach key [lsort [array names array]] {
$json string $key string $array($key)
}

$json map_close
$json map_close
}

#
# array_to_json - convert an array to json
#
proc array_to_json {_array} {
upvar $_array array
upvar $_array array

set json [yajl create #auto -beautify 1]
add_array_to_json $json array
set result [$json get]
rename $json ""
return $result
set json [yajl create #auto -beautify 1]
add_array_to_json $json array
set result [$json get]
rename $json ""
return $result
}

#
Expand All @@ -187,28 +187,28 @@ proc array_to_json {_array} {
# pairs, one object per tuple in the result
#
proc add_pgresult_tuples_to_json {json res} {
$json array_open
set numTuples [pg_result $res -numTuples]
for {set tuple 0} {$tuple < $numTuples} {incr tuple} {
unset -nocomplain row
pg_result $res -tupleArrayWithoutNulls $tuple row
add_array_to_json $json row
}
$json array_close
$json array_open
set numTuples [pg_result $res -numTuples]
for {set tuple 0} {$tuple < $numTuples} {incr tuple} {
unset -nocomplain row
pg_result $res -tupleArrayWithoutNulls $tuple row
add_array_to_json $json row
}
$json array_close
}

#
# pg_select_to_json - given a connection handle and a sql select statement,
# return the corresponding json as an array of objects of tuples
#
proc pg_select_to_json {db sql} {
set json [yajl create #auto -beautify 1]
set res [pg_exec $db $sql]
add_pgresult_tuples_to_json $json $res
pg_result $res -clear
set result [$json get]
rename $json ""
return $result
set json [yajl create #auto -beautify 1]
set res [pg_exec $db $sql]
add_pgresult_tuples_to_json $json $res
pg_result $res -clear
set result [$json get]
rename $json ""
return $result
}

} ;# namespace ::yajl

0 comments on commit 1cb6988

Please sign in to comment.