Class JsonRoleExporter

java.lang.Object
com.tnsai.roles.export.JsonRoleExporter
All Implemented Interfaces:
RoleExporter

public class JsonRoleExporter extends Object implements RoleExporter
Exports Role definitions to JSON format.

Produces a clean JSON representation suitable for:

  • API responses
  • Configuration files
  • Role sharing and import
  • Documentation generation

Example Output


 {
   "name": "Researcher",
   "goal": "Find and analyze information",
   "domain": "Research",
   "version": "1.0.0",
   "responsibilities": {
     "duties": ["Search databases", "Analyze papers"],
     "mustNever": ["Fabricate data"],
     "mustAlways": ["Cite sources"]
   },
   "llm": {
     "provider": "openai",
     "model": "gpt-4o",
     "temperature": 0.7
   },
   "actions": [...]
 }
 
Author:
TnsAI Team
  • Constructor Details

    • JsonRoleExporter

      public JsonRoleExporter()
      Creates a JsonRoleExporter with pretty printing.
    • JsonRoleExporter

      public JsonRoleExporter(boolean prettyPrint, int indentSpaces)
      Creates a JsonRoleExporter with custom formatting.
      Parameters:
      prettyPrint - whether to format output
      indentSpaces - spaces per indent level
  • Method Details

    • export

      public String export(Role role)
      Description copied from interface: RoleExporter
      Exports a Role instance to the target format.
      Specified by:
      export in interface RoleExporter
      Parameters:
      role - the role to export
      Returns:
      exported string representation
    • exportFromClass

      public String exportFromClass(Class<? extends Role> roleClass)
      Description copied from interface: RoleExporter
      Exports a Role class (using annotations) to the target format.
      Specified by:
      exportFromClass in interface RoleExporter
      Parameters:
      roleClass - the role class with annotations
      Returns:
      exported string representation
    • export

      public String export(ExportedRole metadata)
      Description copied from interface: RoleExporter
      Exports role metadata to the target format.
      Specified by:
      export in interface RoleExporter
      Parameters:
      metadata - the extracted role metadata
      Returns:
      exported string representation
    • getFileExtension

      public String getFileExtension()
      Description copied from interface: RoleExporter
      Returns the file extension for this export format.
      Specified by:
      getFileExtension in interface RoleExporter
      Returns:
      file extension (e.g., "json", "yaml", "asl")
    • getMimeType

      public String getMimeType()
      Description copied from interface: RoleExporter
      Returns the MIME type for this export format.
      Specified by:
      getMimeType in interface RoleExporter
      Returns:
      MIME type
    • getFormatName

      public String getFormatName()
      Description copied from interface: RoleExporter
      Returns the format name.
      Specified by:
      getFormatName in interface RoleExporter
      Returns:
      format name (e.g., "JSON", "YAML", "AgentSpeak")