From fdf4f70bce1cd8cd361d34637818c3de54c479e3 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Tue, 21 Apr 2015 03:08:16 -0300 Subject: [PATCH] Add option to save JSON in compact form --- core/src/processing/data/JSONObject.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/src/processing/data/JSONObject.java b/core/src/processing/data/JSONObject.java index f5f02541e..4665d7d51 100644 --- a/core/src/processing/data/JSONObject.java +++ b/core/src/processing/data/JSONObject.java @@ -1554,12 +1554,19 @@ public class JSONObject { public boolean save(File file, String options) { - return write(PApplet.createWriter(file)); + return write(PApplet.createWriter(file), options); } - public boolean write(PrintWriter output) { - output.print(format(2)); + return write(output, null); + } + + public boolean write(PrintWriter output, String options) { + int indentFactor = 2; + if (options != null && options.equals("compact")) { + indentFactor = -1; + } + output.print(format(indentFactor)); output.flush(); return true; }