Prettify adds indentation to a JSON string; minify removes all indentation/whitespace.

prettify(txt, indent = 4)

minify(txt)

Arguments

txt

JSON string

indent

number of spaces to indent

Examples

myjson <- toJSON(cars) cat(myjson)
#> [{"speed":4,"dist":2},{"speed":4,"dist":10},{"speed":7,"dist":4},{"speed":7,"dist":22},{"speed":8,"dist":16},{"speed":9,"dist":10},{"speed":10,"dist":18},{"speed":10,"dist":26},{"speed":10,"dist":34},{"speed":11,"dist":17},{"speed":11,"dist":28},{"speed":12,"dist":14},{"speed":12,"dist":20},{"speed":12,"dist":24},{"speed":12,"dist":28},{"speed":13,"dist":26},{"speed":13,"dist":34},{"speed":13,"dist":34},{"speed":13,"dist":46},{"speed":14,"dist":26},{"speed":14,"dist":36},{"speed":14,"dist":60},{"speed":14,"dist":80},{"speed":15,"dist":20},{"speed":15,"dist":26},{"speed":15,"dist":54},{"speed":16,"dist":32},{"speed":16,"dist":40},{"speed":17,"dist":32},{"speed":17,"dist":40},{"speed":17,"dist":50},{"speed":18,"dist":42},{"speed":18,"dist":56},{"speed":18,"dist":76},{"speed":18,"dist":84},{"speed":19,"dist":36},{"speed":19,"dist":46},{"speed":19,"dist":68},{"speed":20,"dist":32},{"speed":20,"dist":48},{"speed":20,"dist":52},{"speed":20,"dist":56},{"speed":20,"dist":64},{"speed":22,"dist":66},{"speed":23,"dist":54},{"speed":24,"dist":70},{"speed":24,"dist":92},{"speed":24,"dist":93},{"speed":24,"dist":120},{"speed":25,"dist":85}]
prettify(myjson)
#> [ #> { #> "speed": 4, #> "dist": 2 #> }, #> { #> "speed": 4, #> "dist": 10 #> }, #> { #> "speed": 7, #> "dist": 4 #> }, #> { #> "speed": 7, #> "dist": 22 #> }, #> { #> "speed": 8, #> "dist": 16 #> }, #> { #> "speed": 9, #> "dist": 10 #> }, #> { #> "speed": 10, #> "dist": 18 #> }, #> { #> "speed": 10, #> "dist": 26 #> }, #> { #> "speed": 10, #> "dist": 34 #> }, #> { #> "speed": 11, #> "dist": 17 #> }, #> { #> "speed": 11, #> "dist": 28 #> }, #> { #> "speed": 12, #> "dist": 14 #> }, #> { #> "speed": 12, #> "dist": 20 #> }, #> { #> "speed": 12, #> "dist": 24 #> }, #> { #> "speed": 12, #> "dist": 28 #> }, #> { #> "speed": 13, #> "dist": 26 #> }, #> { #> "speed": 13, #> "dist": 34 #> }, #> { #> "speed": 13, #> "dist": 34 #> }, #> { #> "speed": 13, #> "dist": 46 #> }, #> { #> "speed": 14, #> "dist": 26 #> }, #> { #> "speed": 14, #> "dist": 36 #> }, #> { #> "speed": 14, #> "dist": 60 #> }, #> { #> "speed": 14, #> "dist": 80 #> }, #> { #> "speed": 15, #> "dist": 20 #> }, #> { #> "speed": 15, #> "dist": 26 #> }, #> { #> "speed": 15, #> "dist": 54 #> }, #> { #> "speed": 16, #> "dist": 32 #> }, #> { #> "speed": 16, #> "dist": 40 #> }, #> { #> "speed": 17, #> "dist": 32 #> }, #> { #> "speed": 17, #> "dist": 40 #> }, #> { #> "speed": 17, #> "dist": 50 #> }, #> { #> "speed": 18, #> "dist": 42 #> }, #> { #> "speed": 18, #> "dist": 56 #> }, #> { #> "speed": 18, #> "dist": 76 #> }, #> { #> "speed": 18, #> "dist": 84 #> }, #> { #> "speed": 19, #> "dist": 36 #> }, #> { #> "speed": 19, #> "dist": 46 #> }, #> { #> "speed": 19, #> "dist": 68 #> }, #> { #> "speed": 20, #> "dist": 32 #> }, #> { #> "speed": 20, #> "dist": 48 #> }, #> { #> "speed": 20, #> "dist": 52 #> }, #> { #> "speed": 20, #> "dist": 56 #> }, #> { #> "speed": 20, #> "dist": 64 #> }, #> { #> "speed": 22, #> "dist": 66 #> }, #> { #> "speed": 23, #> "dist": 54 #> }, #> { #> "speed": 24, #> "dist": 70 #> }, #> { #> "speed": 24, #> "dist": 92 #> }, #> { #> "speed": 24, #> "dist": 93 #> }, #> { #> "speed": 24, #> "dist": 120 #> }, #> { #> "speed": 25, #> "dist": 85 #> } #> ] #>
minify(myjson)
#> [{"speed":4,"dist":2},{"speed":4,"dist":10},{"speed":7,"dist":4},{"speed":7,"dist":22},{"speed":8,"dist":16},{"speed":9,"dist":10},{"speed":10,"dist":18},{"speed":10,"dist":26},{"speed":10,"dist":34},{"speed":11,"dist":17},{"speed":11,"dist":28},{"speed":12,"dist":14},{"speed":12,"dist":20},{"speed":12,"dist":24},{"speed":12,"dist":28},{"speed":13,"dist":26},{"speed":13,"dist":34},{"speed":13,"dist":34},{"speed":13,"dist":46},{"speed":14,"dist":26},{"speed":14,"dist":36},{"speed":14,"dist":60},{"speed":14,"dist":80},{"speed":15,"dist":20},{"speed":15,"dist":26},{"speed":15,"dist":54},{"speed":16,"dist":32},{"speed":16,"dist":40},{"speed":17,"dist":32},{"speed":17,"dist":40},{"speed":17,"dist":50},{"speed":18,"dist":42},{"speed":18,"dist":56},{"speed":18,"dist":76},{"speed":18,"dist":84},{"speed":19,"dist":36},{"speed":19,"dist":46},{"speed":19,"dist":68},{"speed":20,"dist":32},{"speed":20,"dist":48},{"speed":20,"dist":52},{"speed":20,"dist":56},{"speed":20,"dist":64},{"speed":22,"dist":66},{"speed":23,"dist":54},{"speed":24,"dist":70},{"speed":24,"dist":92},{"speed":24,"dist":93},{"speed":24,"dist":120},{"speed":25,"dist":85}]