Class AsepriteFormat


public final class AsepriteFormat

Java representation of the JSON export format produced by Aseprite.

The Aseprite CLI can export a sprite sheet image together with a JSON sidecar that describes how each frame of the sprite sheet is laid out and how long it should be displayed. See the Aseprite CLI documentation for details.

This class supports both the "hash" (frames as an object map) and the "array" (frames as a JSON array) layouts. When writing, the engine emits the "hash" form, which is the Aseprite default.

Serialization is delegated to JsonUtilities, which is backed by the Jakarta JSON Processing and Jakarta JSON Binding APIs.

  • Constructor Details

    • AsepriteFormat

      public AsepriteFormat()
      Creates an empty Aseprite format instance.
  • Method Details

    • read

      public static AsepriteFormat read(URL url) throws IOException
      Reads an Aseprite JSON document from the given URL.
      Parameters:
      url - The URL of the JSON file.
      Returns:
      The parsed Aseprite format.
      Throws:
      IOException - If the file cannot be read or parsed.
    • read

      public static AsepriteFormat read(Path path) throws IOException
      Reads an Aseprite JSON document from the given path.
      Parameters:
      path - The path to the JSON file.
      Returns:
      The parsed Aseprite format.
      Throws:
      IOException - If the file cannot be read or parsed.
    • parse

      public static AsepriteFormat parse(String json) throws IOException
      Parses an Aseprite JSON document from the given JSON string.
      Parameters:
      json - The JSON text.
      Returns:
      The parsed Aseprite format.
      Throws:
      IOException - If the JSON is malformed or does not represent an Aseprite document.
    • write

      public void write(Path path) throws IOException
      Writes this Aseprite document to the given path as a (pretty-printed) JSON file.
      Parameters:
      path - The destination path.
      Throws:
      IOException - If writing fails.
    • writeToString

      public String writeToString(boolean pretty)
      Writes this Aseprite document as a JSON string.
      Parameters:
      pretty - Whether to format the output with indentation and line breaks.
      Returns:
      The JSON representation.
    • getFrames

      public List<AsepriteFormat.Frame> getFrames()
      Returns:
      The list of frames defined by this document.
    • getImage

      public String getImage()
      Returns:
      The image filename referenced in the document's meta block (may be null).
    • setImage

      public void setImage(String image)
    • getImageWidth

      public int getImageWidth()
      Returns:
      The width of the referenced sprite sheet image, in pixels.
    • setImageWidth

      public void setImageWidth(int imageWidth)
    • getImageHeight

      public int getImageHeight()
      Returns:
      The height of the referenced sprite sheet image, in pixels.
    • setImageHeight

      public void setImageHeight(int imageHeight)
    • getFormat

      public String getFormat()
      Returns:
      The pixel format string from the document's meta block.
    • setFormat

      public void setFormat(String format)
    • getApp

      public String getApp()
    • setApp

      public void setApp(String app)
    • getVersion

      public String getVersion()
    • setVersion

      public void setVersion(String version)