blob: 2982c7c195ce3d8ee7e150a0895d8580723bbd61 [file] [log] [blame]
//-------------------------------------------------------------------------------------------------------
// 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]);
}
}
}