indent json, assumes the input is not yet indented. here is an example:
{
"FastResponseJs":{
"ajaxElements":{
"AjaxMapEntry":[
{
"theKey":{
"@class":"string",
"$":"ajax1a"
},
"theValue":{
"@class":"AjaxEvent",
"ajaxSendFormNames":{
"string":"ajax1"
},
"ajaxEventType":"NORMAL",
"eventName":"onblur",
"ajaxId":"PRLZY5QZ",
"screenElementId":"ajax1a",
"asynchronous":true,
"disableValidation":true
}
},
{
"theKey":{
...
Usage: String formatted = new StringIndenter(jsonString).result();
| Modifier and Type | Field and Description |
|---|---|
| private int | currentNumberOfIndents
current number of indents (times to is the indent |
| private int | endTagIndex
current end tag |
| private String | json
chars to process |
| private StringBuilder | result
result |
| private int | startTagIndex
current start tag |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private int | |
| private static int | Returns: the start tag index of -1 if not found anotheris the char after the start of tag startFrom)find the end tag from json and a start from index |
| private static int | Returns: the start tag index of -1 if not found anotherfind the start tag from json and a start from index either look for a quote, {, [ or scalar. |
| private int | |
| private void | |
| private static boolean | |
| private static boolean | |
| private static boolean | |
| private static boolean | Returns: if it is an instant indentsee if instant indent |
| private void | |
| private boolean | |
| private void | |
| private static String | |
| public String | |
| private void |
| currentNumberOfIndents | back to summary |
|---|---|
| private int currentNumberOfIndents current number of indents (times to is the indent | |
| endTagIndex | back to summary |
|---|---|
| private int endTagIndex current end tag | |
| json | back to summary |
|---|---|
| private String json chars to process | |
| result | back to summary |
|---|---|
| private StringBuilder result result | |
| startTagIndex | back to summary |
|---|---|
| private int startTagIndex current start tag | |
| StringIndenter | back to summary |
|---|---|
public StringIndenter(String theJson)
| |
| findEndTagIndex | back to summary |
|---|---|
| private int findEndTagIndex() after the last start tag, find the next end start tag
| |
| findNextEndTagIndex | back to summary |
|---|---|
| private static int findNextEndTagIndex(String json, int startFrom) find the end tag from json and a start from index
| |
| findNextStartTagIndex | back to summary |
|---|---|
| private static int findNextStartTagIndex(String json, int startFrom) find the start tag from json and a start from index either look for a quote, {, [ or scalar. generally not whitespace
| |
| findStartTagIndex | back to summary |
|---|---|
| private int findStartTagIndex() after the last end tag, find the next start tag
| |
| indent | back to summary |
|---|---|
| private void indent() indent the string | |
| instantIndent | back to summary |
|---|---|
| private static boolean instantIndent(String json, int index) see if instant indent
| |
| instantNewline | back to summary |
|---|---|
| private static boolean instantNewline(String json, int index) see if instant indent
| |
| instantUnindent | back to summary |
|---|---|
| private static boolean instantUnindent(String json, int index) see if instant unindent
| |
| instantUnindentTwoChars | back to summary |
|---|---|
| private static boolean instantUnindentTwoChars(String json, int index) see if instant indent
| |
| newlineIndent | back to summary |
|---|---|
| private void newlineIndent() put a newline and indent | |
| onNewline | back to summary |
|---|---|
| private boolean onNewline() see if current pos is on newline
| |
| printNewlineIndent | back to summary |
|---|---|
| private void printNewlineIndent(int start, int end) put a newline and indent | |
| repeat | back to summary |
|---|---|
| private static String repeat(String theString, int times) repeat a string a certain number of times.
| |
| result | back to summary |
|---|---|
| public String result() get the result
| |
| unindent | back to summary |
|---|---|
| private void unindent() unindent a previous indent if it is there | |