Module json5

Class JSONStringify

java.lang.Object
at.syntaxerror.json5.JSONStringify

public class JSONStringify extends Object
A utility class for serializing JSONObjects and JSONArrays into their string representations
Author:
SyntaxError404
  • Method Details

    • toString

      public static String toString(JSONObject object, int indentFactor, JSONOptions options)
      Converts a JSONObject into its string representation. The indentation factor enables pretty-printing and defines how many spaces (' ') should be placed before each key/value pair. A factor of < 1 disables pretty-printing and discards any optional whitespace characters.

      indentFactor = 2:

       {
         "key0": "value0",
         "key1": {
           "nested": 123
         },
         "key2": false
       }
       

      indentFactor = 0:

       {"key0":"value0","key1":{"nested":123},"key2":false}
       
      Parameters:
      object - the JSONObject
      indentFactor - the indentation factor
      options - the options for stringifying
      Returns:
      the string representation
      Since:
      1.1.0
    • toString

      public static String toString(JSONArray array, int indentFactor, JSONOptions options)
      Converts a JSONArray into its string representation. The indentation factor enables pretty-printing and defines how many spaces (' ') should be placed before each value. A factor of < 1 disables pretty-printing and discards any optional whitespace characters.

      indentFactor = 2:

       [
         "value",
         {
           "nested": 123
         },
         false
       ]
       

      indentFactor = 0:

       ["value",{"nested":123},false]
       
      Parameters:
      array - the JSONArray
      indentFactor - the indentation factor
      options - the options for stringifying
      Returns:
      the string representation
      Since:
      1.1.0
    • toString

      public static String toString(JSONObject object, int indentFactor)
      Converts a JSONObject into its string representation. The indentation factor enables pretty-printing and defines how many spaces (' ') should be placed before each key/value pair. A factor of < 1 disables pretty-printing and discards any optional whitespace characters.

      indentFactor = 2:

       {
         "key0": "value0",
         "key1": {
           "nested": 123
         },
         "key2": false
       }
       

      indentFactor = 0:

       {"key0":"value0","key1":{"nested":123},"key2":false}
       
      This uses the default options
      Parameters:
      object - the JSONObject
      indentFactor - the indentation factor
      Returns:
      the string representation
    • toString

      public static String toString(JSONArray array, int indentFactor)
      Converts a JSONArray into its string representation. The indentation factor enables pretty-printing and defines how many spaces (' ') should be placed before each value. A factor of < 1 disables pretty-printing and discards any optional whitespace characters.

      indentFactor = 2:

       [
         "value",
         {
           "nested": 123
         },
         false
       ]
       

      indentFactor = 0:

       ["value",{"nested":123},false]
       
      This uses the default options
      Parameters:
      array - the JSONArray
      indentFactor - the indentation factor
      Returns:
      the string representation