summaryrefslogtreecommitdiff
path: root/jsonrpc
diff options
context:
space:
mode:
authorDerrell Lipman <derrell@samba.org>2006-10-02 02:36:27 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:20:28 -0500
commitad60ec590765607077ae6141b4613a762f69a539 (patch)
treee79ac63f723a384340507fd72fb98d68d0307800 /jsonrpc
parent127c96f49905291b4566c2a1bc25d882ae111466 (diff)
downloadsamba-ad60ec590765607077ae6141b4613a762f69a539.tar.gz
samba-ad60ec590765607077ae6141b4613a762f69a539.tar.bz2
samba-ad60ec590765607077ae6141b4613a762f69a539.zip
r19019: Add a parser for javascript literals. This is implemented for parsing JSON
strings, but is generally useful for creating ejs variables from object or array literals, which aren't supported in the old version of ejs that we're using. This parser is implemented in C, but is callable from an ejs script via literal_to_var(). (This used to be commit 82fdcd9339a8ffb1016b96c06f7d6580aa759174)
Diffstat (limited to 'jsonrpc')
-rw-r--r--jsonrpc/json.esp34
1 files changed, 32 insertions, 2 deletions
diff --git a/jsonrpc/json.esp b/jsonrpc/json.esp
index d06a173f0f..ad0e13a6c3 100644
--- a/jsonrpc/json.esp
+++ b/jsonrpc/json.esp
@@ -137,6 +137,9 @@ Json = new Object();
Json.encode = _encode;
_encode = null;
+/* Json.decode(): decode a string into its object form */
+Json.decode = literal_to_var;
+
/* Internal stuff, not for external access */
Json._internal = new Object();
@@ -191,7 +194,7 @@ Json._internal.convert['\x1f'] = '\\u001f';
/* Test it */
libinclude("base.js");
-function testIt()
+function testFormat()
{
var test = new Object();
test.int = 23;
@@ -208,6 +211,33 @@ function testIt()
test.obj.array[1] = 223;
printf("%s\n", Json.encode(test));
}
-//testIt();
+
+function testParse()
+{
+ var s;
+
+ s = '{ "x" : 23 }';
+ obj = Json.decode(s);
+ printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj));
+
+ s = '{ "x" : [ 23, 42] }';
+ obj = Json.decode(s);
+ printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj));
+
+ s = '[ 13, 19, { "x" : [ 23, 42] }, 223 ]';
+ obj = Json.decode(s);
+ printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj));
+
+ s = '{ "x" : [ "hi" ] }';
+ obj = Json.decode(s);
+ printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj));
+
+ s = '[ 13, 19, { "x" : [ 23, 42, { "y":{"a":"hello", "b":"world", "c":[1,2,3]}}] }, 223 ]';
+ obj = Json.decode(s);
+ printf("Decode/encode of\n\t%s\nyielded\n\t%s\n\n", s, Json.encode(obj));
+}
+
+//testFormat();
+testParse();
%>