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

Into the Box 2025 | Plan Your Trip With Us!

Into the Box 2025 | Plan Your Trip With Us!

Are you ready to join us for Into the Box 2025 from April 30th to May 2nd in Washington, D.C.? Let’s make your trip planning as smooth as possible. Here you’ll find Airfare discounts, Hotel Deals and fun things to do to the the best out of your trip to D.C.

Maria Jose Herrera
Maria Jose Herrera
January 29, 2025
TestBox v6.1.0 Release

TestBox v6.1.0 Release

We’re super excited to announce the release of TestBox 6.1.0! This release introduces native support for BoxLang without the need for a compatibility mode, unlocking new possibilities for developers embracing BoxLang’s dynamic capabilities. Alongside this exciting update, we’ve added valuable features, improved functionality, and resolved key issues to ensure a smoother and more robust testing experience. Dive into the details and see how TestBox 6.1.0 makes your testing even more seamless and efficient!

Luis Majano
Luis Majano
January 28, 2025
Into the Box Round 1 of Sessions and Workshops are now out!

Into the Box Round 1 of Sessions and Workshops are now out!

Our first round of sessions and workshops for Into the Box 2025 is here! Get ready to dive into a world of modern web development with hands-on workshops and engaging sessions led by Ortus Solutions and Community CFML and BoxLang experts. Visit intothebox.org to explore what’s in store—this is just the beginning, with much more content coming soon!

Maria Jose Herrera
Maria Jose Herrera
January 20, 2025