Skip to content

Commit 364b55b

Browse files
authored
Ensure string escape sequences are preserved (#24)
1 parent af0fceb commit 364b55b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

projects/demo/src/app/app.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ <h3>Simple Types</h3>
3838
<div class="json-container">
3939
<ngx-json-treeview [json]="13" />
4040
<ngx-json-treeview [json]="'hello, world!'" />
41+
<ngx-json-treeview [json]="'hello, world!\nanother line!'" />
4142
<ngx-json-treeview [json]="true" />
4243
<ngx-json-treeview [json]="null" />
4344
<ngx-json-treeview [json]="{}" />

projects/demo/src/app/app.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class AppComponent {
1212

1313
baseObj = {
1414
string: 'Hello World',
15+
stringPre: 'Hello\nWorld\n\tAnother line',
1516
number: 1234567890,
1617
boolean: true,
1718
url: 'http://www.google.com',
@@ -51,6 +52,11 @@ export class AppComponent {
5152
}
5253

5354
stringify(obj: any) {
54-
return typeof obj === 'function' ? '' + obj : JSON.stringify(obj, null, 2);
55+
if (typeof obj === 'function') {
56+
return '' + obj;
57+
} else if (typeof obj === 'string') {
58+
return obj;
59+
}
60+
return JSON.stringify(obj, null, 2);
5561
}
5662
}

projects/ngx-json-treeview/src/lib/ngx-json-treeview.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class NgxJsonTreeviewComponent {
245245
break;
246246
case 'string':
247247
segment.type = 'string';
248-
segment.description = '"' + segment.value + '"';
248+
segment.description = JSON.stringify(segment.value);
249249
break;
250250
case 'undefined':
251251
segment.type = 'undefined';

0 commit comments

Comments
 (0)