java.lang.Object
de.ralleytn.simple.json.JSONFormatter
Can format and minimize JSON data.
- Since:
- 1.0.0
- Version:
- 2.1.0
- Author:
- Ralph Niemitz/RalleYTN(ralph.niemitz@gmx.de)
-
Constructor Summary
ConstructorDescriptionConstructs a new JSONFormatter.JSONFormatter
(int indent, boolean useCRLF, boolean useTabs) Constructs a new JSONFormatter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Formats minimized JSON data.void
format
(JSONObject object, Writer writer) Formats minimized JSON data.void
Formats minimized JSON data.Formats minimized JSON data.int
void
Minimizes formatted JSON data.Minimizes formatted JSON data.void
setIndent
(int indent) Sets the indent.void
setUseCRLF
(boolean crlf) Sets whether a CRLF or a LF line break should be used.void
setUseTabs
(boolean tabs) Sets whether a tabulator or space should be used for the indent.boolean
usesCRLF()
boolean
usesTabs()
-
Constructor Details
-
JSONFormatter
public JSONFormatter()Constructs a new JSONFormatter. Default indent is1
and tabulators will be used for the indent.- Since:
- 2.0.0
-
JSONFormatter
public JSONFormatter(int indent, boolean useCRLF, boolean useTabs) Constructs a new JSONFormatter.- Parameters:
indent
- the character count of spaces/tabs used for the indentuseCRLF
-true
= CRLF (Windows linebreak),false
= LF (Unix linebreak)useTabs
-true
= tabulator,false
= space- Since:
- 2.1.0
-
-
Method Details
-
setUseCRLF
public void setUseCRLF(boolean crlf) Sets whether a CRLF or a LF line break should be used.- Parameters:
crlf
-true
= CRLF (Windows linebreak),false
= LF (Unix linebreak)- Since:
- 2.0.0
-
setUseTabs
public void setUseTabs(boolean tabs) Sets whether a tabulator or space should be used for the indent.- Parameters:
tabs
-true
= tabulator,false
= space- Since:
- 2.0.0
-
setIndent
public void setIndent(int indent) Sets the indent.- Parameters:
indent
- the character count of spaces/tabs used for the indent- Since:
- 2.0.0
-
format
Formats minimized JSON data. Do not try to format already formatted JSON. The result does not look good.- Parameters:
reader
- the Reader with the JSON datawriter
- the Writer on which the formatted JSON data should be written- Throws:
IOException
- if an I/O error occurs- Since:
- 1.0.0
-
format
Formats minimized JSON data. Do not try to format already formatted JSON. The result does not look good.- Parameters:
json
- the JSON data that should be formatted- Returns:
- the formatted JSON data
- Since:
- 1.0.0
-
format
Formats minimized JSON data. Do not try to format already formatted JSON. The result does not look good.- Parameters:
object
- The JSON object that is meant to be formattedwriter
- The writer on which the formatted JSON string will be written- Throws:
IOException
- if an I/O error occurs- Since:
- 2.1.0
-
format
Formats minimized JSON data. Do not try to format already formatted JSON. The result does not look good.- Parameters:
array
- The JSON array that is meant to be formattedwriter
- The writer on which the formatted JSON string will be written- Throws:
IOException
- if an I/O error occurs- Since:
- 2.1.0
-
minimize
Minimizes formatted JSON data.- Parameters:
reader
- the Reader with the formatted JSON datawriter
- the Writer on which the minimized JSON data should be written- Throws:
IOException
- if an I/O error occurs- Since:
- 1.0.0
-
minimize
Minimizes formatted JSON data.- Parameters:
json
- the formatted JSON data- Returns:
- the minimized JSON data
- Since:
- 1.0.0
-
usesCRLF
public boolean usesCRLF()- Returns:
true
when CRLF line breaks are used for formatting, elsefalse
- Since:
- 2.0.0
-
usesTabs
public boolean usesTabs()- Returns:
true
if tabulators are used for the indent, elsefalse
- Since:
- 2.0.0
-
getIndent
public int getIndent()- Returns:
- the indent
- Since:
- 2.0.0
-