Why use XML to Crystal instead of JSON to Crystal?
Choose XML to Crystal when the source payload is XML and the generated classes need to reflect nested elements, repeated nodes, and document-style structure rather than JSON arrays and objects.
Generate Crystal classes from XML samples when your service, CLI, or ingestion job still works with XML feeds and wants readable typed transport models.
<user>
<id>101</id>
<name>Ada Lovelace</name>
<active>true</active>
<roles>
<role>admin</role>
<role>editor</role>
</roles>
<profile>
<email>ada@example.com</email>
<score>9.8</score>
</profile>
</user>
require "json"
class UserModel
include JSON::Serializable
property id : Int32
property name : String
property active : Bool
property roles : Array(String)
end
Choose XML to Crystal when the source payload is XML and the generated classes need to reflect nested elements, repeated nodes, and document-style structure rather than JSON arrays and objects.
Yes. Nested XML elements are expanded into child classes, and repeated nodes are inferred into collection fields based on the parsed XML sample.