Class JSONUtils

Object
JSONUtils

public class JSONUtils extends Object
Contains methods for dealing with JSON objects.
Since:
1.8
Author:
LazyWizard
  • Method Details

    • clear

      public static void clear(JSONObject toClear)
      Clears all entries in a JSONObject.
      Parameters:
      toClear - The JSONObject to clear.
      Since:
      2.4
    • toColor

      public static Color toColor(JSONArray array) throws JSONException
      Transform a JSONArray of ints into a Color. Use with SettingsAPI's file loading methods to read a color from a file.
      Parameters:
      array - The JSONArray to convert to a Color.
      Returns:
      A Color using array's color values.
      Throws:
      JSONException - if array doesn't contain three or more ints
      Since:
      1.8
    • loadCommonJSON

      public static JSONUtils.CommonDataJSONObject loadCommonJSON(String filename, @Nullable String defaultJSONPath) throws IOException, JSONException
      Loads a JSON file from common data, or creates it, populates it with default values, and saves it to disk if it does not already exist.
      Parameters:
      filename - The filename to load (or create) in common data.
      defaultJSONPath - The path to a default JSON in a mod folder. If filename does not already exist in the common data directory, it will be created and populated with the contents of this JSON file.
      Returns:
      A wrapper around a JSONObject that allows saving to common data.
      Throws:
      IOException
      JSONException
      Since:
      2.4
    • loadCommonJSON

      public static JSONUtils.CommonDataJSONObject loadCommonJSON(String filename) throws IOException, JSONException
      Loads a JSON file from common data, or creates it if it does not already exist.
      Parameters:
      filename - The filename to load (or create) in common data.
      Returns:
      A wrapper around a JSONObject that allows saving to common data.
      Throws:
      IOException
      JSONException
      Since:
      2.4