Class JsonToXmlExtensions

java.lang.Object
io.github.astrapi69.json.JsonToXmlExtensions

public final class JsonToXmlExtensions extends Object
The class JsonToXmlExtensions helps to transform a given json string to an xml string.
  • Method Details

    • toXml

      public static String toXml(String jsonString) throws org.json.JSONException
      Transform the given json as String object to a xml as String object
      Parameters:
      jsonString - the json as String object
      Returns:
      the transformed xml as String object
      Throws:
      org.json.JSONException - if there is a syntax error in the source string or a duplicated key
    • toXml

      public static String toXml(String jsonString, int indent) throws org.json.JSONException
      Transform the given json as String object to a xml as String object
      Parameters:
      jsonString - the json as String object
      indent - the indent is the number of spaces to add to each level of indentation
      Returns:
      the transformed xml as String object
      Throws:
      org.json.JSONException - if there is a syntax error in the source string or a duplicated key
    • toXml

      public static String toXml(String jsonString, int indent, boolean withHeader) throws org.json.JSONException
      Transform the given json as String object to a xml as String object
      Parameters:
      jsonString - the json as String object
      indent - the indent is the number of spaces to add to each level of indentation
      withHeader - the flag that indicates if an xml header should be added
      Returns:
      the transformed xml as String object
      Throws:
      org.json.JSONException - if there is a syntax error in the source string or a duplicated key
    • toXml

      public static String toXml(String jsonString, int indent, boolean withHeader, boolean withRootTag, String rootTagName) throws org.json.JSONException
      Transform the given json as String object to a xml as String object
      Parameters:
      jsonString - the json as String object
      indent - the indent is the number of spaces to add to each level of indentation
      withHeader - the flag that indicates if a xml header should be added
      withRootTag - the flag that indicates if a root tag will be added
      rootTagName - the name of the root tag
      Returns:
      the transformed xml as String object
      Throws:
      org.json.JSONException - if there is a syntax error in the source string or a duplicated key