Blog

BoxLang YAML Support has landed

Luis Majano January 28, 2025

Spread the word

Luis Majano

January 28, 2025

Spread the word


Share your thoughts

We’re thrilled to introduce the bx-yaml module for BoxLang!

This powerful new module brings seamless YAML parsing and emitting capabilities to BoxLang. You can now effortlessly serialize BoxLang native types—including structs, queries, arrays, classes, and more—into YAML. The same simplicity applies to deserialization, making it easy to work with YAML data in your BoxLang applications.

Key Features

  • Serialize to YAML from native BoxLang types
  • Custom serialization of BoxLang classes
  • Serialize stream directly to a file
  • Deserialize YAML to native BoxLang Types
  • Deserialize a YAML stream from a file to BoxLang Types

Reporting Issues

If you encounter any issues or have feature requests, please report them to:

Please send us your feedback and testing!

Quick Usage

This module registers the following BIFS:

  • yamlSerialize( content, [filepath], [charset=utf8] ):yaml : Serialize a BoxLang variable into a YAML string. You can also serialize to a file if you provide a file path.
  • yamlDeserialize( content ):any : Deserialize a YAML string into a BoxLang variable.
  • yamlDeserializeFile( filepath, [charset=utf8] ):any : Deserialize a YAML file into a BoxLang variable.

Here is a simple example:

// Serialize a BoxLang structure into a YAML string
yaml = yamlSerialize( { name="Luis", age=21, city="Orlando" } );
// Serialize a more complex structure
yaml = yamlSerialize( { name="Luis", age=21, city="Orlando", address={ street="1234", city="Orlando", state="FL" } } );

// Deserialize a YAML string into a BoxLang structure
data = yamlDeserialize( yaml );

// Deserialize a YAML file into a BoxLang structure
data = yamlDeserializeFile( "data.yml" );

BoxLang Class Serialization

BoxLang classes will be serialized as a structure according to its properties. However it must adhere to the following rules:

  • The class must have a serializable = true annotation. or none at all, that is the default.
  • The property must have a serializable = true annotation or none at all, that is the default.
  • The property must NOT exist in the yamlExclude list in the class or the parent class.
  • The property must NOT have a yamlExclude annotation.

BoxLang Class Custom Serialization

If you are serializing BoxLang classes, you can implement the toYAML() method in your classes to provide a custom serialization. Here is an example:

class {

	function init( required name="", required age=0, required city="" ){
		variables.name = arguments.name;
		variables.age = arguments.age;
		variables.city = arguments.city;
		return this;
	}

	function toYAML(){
		return { name=variables.name, city=variables.city } );
	}

}

Add Your Comment

Recent Entries

Ortus Solutions Returns to CFCamp as Platinum Sponsor – Join Us to Redefine the Future with BoxLang!

Ortus Solutions Returns to CFCamp as Platinum Sponsor – Join Us to Redefine the Future with BoxLang!

We’re thrilled to announce that Ortus Solutions and BoxLang will once again join CFCamp as Platinum Sponsors for the 2025 edition. As passionate advocates of innovation in the CFML and modern JVM space, we’re proud to keep pushing boundaries—and this year is shaping up to be our biggest presence yet.

Day 1 Keynote by Luis Majano

CFCamp 2025 will kick off with a keynote delivered by none other than our CEO and BoxLang creator, Luis Majano. Join...

Cristobal Escobar
Cristobal Escobar
April 25, 2025
Must-See Into the Box 2025 Sessions for CommandBox Users!

Must-See Into the Box 2025 Sessions for CommandBox Users!

Power Up your CommandBox experience and practices at Into the Box 2025

Want to get hands-on with the new CommandBox features or learn how others are pushing it to the next level? These are the must-see sessions at ITB 2025 if you're a CommandBox user:

Maria Jose Herrera
Maria Jose Herrera
April 21, 2025
Must-See ITB 2025 Sessions for TestBox Users!

Must-See ITB 2025 Sessions for TestBox Users!

Are you a fan of TestBox or looking to level up your testing game in 2025? Whether you're just getting started with unit testing or you're already building advanced specs for ColdBox and BoxLang apps, Into the Box 2025 has an exciting lineup tailored just for you. Into the Box 2025 has an exciting lineup tailored just for you. With the recent launch of TestBox 6.3.0 we have amazing new tools, features and tips and tricks to get your testing experience to the next level, review our sessions and test like a pro efficiently and easy!

From hands-on testing strategies to BoxLang innovations, here are the sessions you won’t want to miss this May — and why they matter to you as a TestBox user.

Maria Jose Herrera
Maria Jose Herrera
April 17, 2025