The YAML_SERIALIZE function takes a regular IDL variable, or an IDL data structure such as a YAML object class, or a HASH or LIST, and converts it into a scalar IDL string containing the YAML (YAML Ain't Markup Language).

This routine is written in the IDL language. Its source code can be found in the file YAML_serialize.pro in the lib/datatypes subdirectory of the IDL distribution.

Examples


Convert a list of IDL values into a YAML string

mylist = LIST(!TRUE, !NULL, 42, 3.14, "Hello")
YAML = YAML_SERIALIZE(mylist)
PRINT, YAML

IDL prints:

- true
- null
- 42
- 3.1400001
- Hello

Convert a hash of key-value pairs into a YAML string

myhash = HASH("Planet", "Jupiter", "Index", 5, "Mass", 1.9d27, "Units", "kg")
YAML = YAML_SERIALIZE(myhash)
PRINT, YAML

IDL prints:

Planet: Jupiter
Index: 5
Mass: 1.9e+27
Units: kg

For more examples see YAML_PARSE.

Syntax


Result = YAML_SERIALIZE(Value)

Return Value


The result is a scalar IDL string containing the YAML, with newlines encoded as \n characters. See below fo details on how IDL variables are converted to YAML items.

Arguments


Value

The IDL variable to be converted to YAML. Value must be a regular IDL variable, one of the IDL container classes such as List, Hash, Dictionary, OrderedHash, or one of the YAML classes.

Keywords


None

Conversion of YAML Data


When converting IDL variables into YAML streams, the following rules are used:

IDL Variable Type YAML Item Notes
YAML_Multidoc Multiple Documents Optional COMMENTS, GLOBAL_TAGS
YAML_Stream_Map

Document with mapping

Optional COMMENTS, GLOBAL_TAGS, TAG
YAML_Stream_Sequence

Document with sequence

Optional COMMENTS, GLOBAL_TAGS, TAG

YAML_Map

Mapping

Optional ANCHOR, TAG properties

OrderedHash, Dictionary, or Hash Mapping  
YAML_Sequence Sequence

Optional ANCHOR, TAG properties

List Sequence  
Byte array (not boolean) !!binary with base64  

IDL array of any allowed type

Sequence

 

YAML_Value Scalar value

Optional ANCHOR, TAG properties

YAML_Alias Alias (reference) ALIAS property
String String

Strings that might match a number or null will be quoted

!NULL null  
Boolean

false or true

 
Scalar byte or integer value Integer  
BigInteger Integer  
Floating-point number Floating-point number  
Complex or Double complex Complex of form A+Bj  

Conformance


See YAML_PARSE for details on conformance to the YAML standard.

Additional Examples


See YAML_PARSE for additional examples.

Version History


8.9

Introduced

See Also


YAML_Alias, YAML_Map, YAML_Sequence, YAML_Multidoc, YAML_Stream_Map, YAML_Stream_Sequence, YAML_Value, YAML_PARSE