Tip for Pretty JSON

We initialize the simulator with small vectors of integers that look better in formatted JSON if they appear all on the same line. We achieve this by post-processing the stringify results.

We desire this.

{ "city": "Fort Wayne", "zip": 323, "pop": 373000, "lat": 41, "lon": -85.16, "path": [341,322,324,316,321,314,317,333], "route": [ [321,322,323,341,324,324,324,324,324], [316,323,333,341,0,0,0,0,0], [321,322,323,324,0,0,0,0,0] ] }

But get this.

{ "city": "Fort Wayne", "zip": 323, "pop": 373000, "lat": 41, "lon": -85.16, "path": [ 341, 322, 324, 316, 321, 314, 317, 333 ], "route": [ [ 321, 322, 323, 341, 324, 324, 324, 324, 324 ], [ 316, 323, 333, 341, ... ] ]

So we apply these post processing replacements.

console.log(JSON.stringify(p,null,2) .replace(/(,|\[)[\r\n\s]*(\d)/g,"$1$2") .replace(/(\d)[\r\n\s]*\]/g,"$1]"))

This removes newlines and white space from before and then after the list of numbers.