Skip to content

Commit e940be3

Browse files
committed
Try/Catch
1 parent a3e7ac2 commit e940be3

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

extension/src/json-viewer/jsl-format.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,31 @@ jsl.format = (function () {
1515
var currentposition = startingposition + 1;
1616
var inString = false;
1717
var num_opened = 1;
18-
while (num_opened > 0 && currentposition < jsonstring.length) {
19-
var currentChar = jsonstring.charAt(currentposition)
20-
switch (currentChar) {
21-
case '[':
22-
if(!inString){
23-
num_opened++;
24-
}
25-
break;
26-
case ']':
27-
if(!inString){
28-
num_opened--;
29-
}
30-
break;
31-
case '"':
32-
inString = !inString;
33-
break;
18+
try{
19+
while (num_opened > 0 && currentposition < jsonstring.length) {
20+
var currentChar = jsonstring.charAt(currentposition)
21+
switch (currentChar) {
22+
case '[':
23+
if(!inString){
24+
num_opened++;
25+
}
26+
break;
27+
case ']':
28+
if(!inString){
29+
num_opened--;
30+
}
31+
break;
32+
case '"':
33+
inString = !inString;
34+
break;
35+
}
36+
currentposition++;
3437
}
35-
currentposition++;
38+
return JSON.parse(jsonstring.substring(startingposition,currentposition)).length;
39+
}
40+
catch(err){
41+
return null;
3642
}
37-
return JSON.parse(jsonstring.substring(startingposition,currentposition)).length;
3843
}
3944
function formatJson(json, options) {
4045
options = options || {};
@@ -61,7 +66,10 @@ jsl.format = (function () {
6166
if (!inString) {
6267
if (indentCStyle) newJson += "\n" + repeat(tab, indentLevel);
6368
if(currentChar === "["){
64-
newJson += "Array[" + getSizeOfArray(json,i) + "]";
69+
var arraySize = getSizeOfArray(json,i);
70+
if(arraySize !== null){
71+
newJson += "Array[" + arraySize + "]";
72+
}
6573
}
6674
newJson += currentChar;
6775

0 commit comments

Comments
 (0)