diff options
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/modules/wsgi/jsonutil.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/sca-cpp/trunk/modules/wsgi/jsonutil.py b/sca-cpp/trunk/modules/wsgi/jsonutil.py index f69559de54..ad8f5fcc6b 100644 --- a/sca-cpp/trunk/modules/wsgi/jsonutil.py +++ b/sca-cpp/trunk/modules/wsgi/jsonutil.py @@ -64,7 +64,14 @@ def jsValToValue(jsv): if isinstance(jsv, basestring): return str(jsv) return jsv - + +# Return true if a list of strings contains a JSON document +def isJSON(l): + if isNil(l): + return False + s = car(l)[0:1] + return s == "[" or s == "{" + # Convert a list of strings representing a JSON document to a list of values def readJSON(l): s = StringIO() @@ -108,7 +115,10 @@ def valuesToJSProperties(o, l): # Convert a list of values to a list of strings representing a JSON document def writeJSON(l): - jsv = valuesToJSProperties({}, l) + if isJSArray(l): + jsv = valuesToJSElements(list(range(0, len(l))), l, 0) + else: + jsv = valuesToJSProperties({}, l) s = json.dumps(jsv, separators=(',',':')) return (s,) |