Skip to content

Commit 7117819

Browse files
committed
Add IJsonFileStringifyOptions.prettyFormatting
1 parent 37fb401 commit 7117819

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎libraries/node-core-library/src/JsonFile.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export interface IJsonFileStringifyOptions {
1818
* If true, then "\n" will be used for newlines instead of the default "\r\n".
1919
*/
2020
newlineConversion?: NewlineKind;
21+
22+
/**
23+
* If true, then the JJU library will be used to improve the text formatting.
24+
* Note that this is slightly slower than the native JSON.stringify() implementation.
25+
*/
26+
prettyFormatting?: boolean;
2127
}
2228

2329
/**
@@ -94,7 +100,17 @@ export class JsonFile {
94100
*/
95101
public static stringify(jsonObject: Object, options?: IJsonFileStringifyOptions): string {
96102
JsonFile.validateNoUndefinedMembers(jsonObject);
97-
const stringified: string = JSON.stringify(jsonObject, undefined, 2) + '\n';
103+
104+
let stringified: string;
105+
106+
if (options && options.prettyFormatting) {
107+
stringified = jju.stringify(jsonObject, {
108+
mode: 'json',
109+
indent: 2
110+
}) + '\n';
111+
} else {
112+
stringified = JSON.stringify(jsonObject, undefined, 2) + '\n';
113+
}
98114

99115
if (options && options.newlineConversion) {
100116
switch (options.newlineConversion) {

0 commit comments

Comments
 (0)