forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple.stringify.js
More file actions
47 lines (38 loc) · 11.8 KB
/
simple.stringify.js
File metadata and controls
47 lines (38 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
var jsonBlobL1AsString = "{\"a\":1, \"b\":2, \"c\":\"\", \"d\":\"\\\"\"}"
var jsonBlobL2AsString = "{\"a\":{\"aa\":10, \"ab\":11}, \"b\":{\"ba\":\"this is a test!\", \"bb\":\"a\"}}"
var jsonLongTransformedBlobL2AsString = "{\"a\":{\"aa\":10, \"ab\":11}, \"b\":{\"ba\":\"this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!\\n\", \"bb\":\"a\"}}"
var jsonLongDirectBlobL2AsString = "{\"a\":{\"a\\ta\":10, \"ab\":11}, \"b\":{\"ba\":\"this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!this is a very long string test!\", \"bb\":\"a\"}}"
TraverseAndPrint("level 1:", jsonBlobL1AsString, false);
TraverseAndPrint("level 1:", jsonBlobL2AsString, false);
TraverseAndPrint("level 1+:", jsonLongDirectBlobL2AsString, true);
TraverseAndPrint("level 1+:", jsonLongTransformedBlobL2AsString, true);
TraverseAndPrint("level 1:", jsonBlobL2AsString, false);
function TraverseAndPrint(msg, str, doRecurse) {
WScript.Echo("---------------");
WScript.Echo(msg);
WScript.Echo(str);
var json = JSON.parse(str);
str = "foo";
WScript.Echo("JSON.Parse result - " + json);
TraverseJSONObject(msg, 1, json, doRecurse);
WScript.Echo("---------------");
WScript.Echo("stringify: " + JSON.stringify(json));
WScript.Echo("---------------");
}
function TraverseJSONObject(msg, level, o, doRecurse) {
doRecurse = doRecurse || false;
var sp = "";
for(var i=1; i<level; i++) {
sp += " ";
}
for(var l in o) {
WScript.Echo(msg + sp + l + ": " + o[l]);
if (doRecurse) {
TraverseJSONObject(msg, level+1, o[l]);
}
}
}