What is JSON to Perl Class Generator?
This tool converts JSON data into Perl class definitions using Moose or Moo. It automatically maps JSON types to Perl Moose type constraints and generates properly structured packages with attribute definitions.
How to Use
- Set the package namespace prefix
- Choose accessor style (read-only or read-write)
- Select Moose or Moo framework
- Paste your JSON data and click "Generate"
Why Use This Tool?
Tips & Best Practices
- Moose provides more features, Moo is lighter weight
- Use "ro" for immutable data, "rw" for mutable
- Nested objects become separate Perl packages
- Arrays get ArrayRef type constraints
Frequently Asked Questions
How are JSON types mapped to Perl Moose types?
JSON strings → Str, integers → Int, floats → Num, booleans → Bool, null → Maybe[Item], arrays → ArrayRef[Type] or ArrayRef for empty arrays, nested objects → separate Perl packages referenced by name.
What is the difference between Moose and Moo?
Moose is a full-featured postmodern object system for Perl 5 with metaclass protocol, type coercion, and method modifiers. Moo is a lightweight alternative that provides most of the same features with less overhead. Moo does not support namespace::autoclean or meta->make_immutable.
How are nested objects handled?
Nested JSON objects are converted to separate Perl packages with their own attribute definitions. They are ordered children-first so that referenced packages are defined before the packages that use them. The parent package references the nested package by name in its type constraint.
What does the package prefix do?
The package prefix sets the namespace for generated packages. For example, with prefix "MyApp::", a "Root" class becomes "MyApp::Root". This follows Perl convention of organizing modules under a namespace hierarchy using "::" as the separator.
Is my data sent to a server?
No, all processing happens entirely in your browser. Your JSON data never leaves your device.