- YAML Tutorial
- YAML - Home
- YAML – Introduction
- YAML – Basics
- YAML – Indentation and Separation
- YAML – Comments
- YAML – Collections and Structures
- YAML – Scalars and Tags
- YAML – Full Length Example
- YAML – Processes
- YAML – Information Models
- YAML – Syntax Characters
- YAML – Syntax Primitives
- YAML – Character Streams
- YAML – Node Properties
- YAML – Block Scalar Header
- YAML – Flow Styles
- YAML – Block Styles
- YAML – Sequence Styles
- YAML – Flow Mappings
- YAML – Block Sequences
- YAML – Failsafe Schema
- YAML – JSON Schema
- YAML Useful Resources
- YAML - Quick Guide
- YAML - Useful Resources
- YAML - Discussion
YAML - Full Length Example
The following full-length example specifies the construct of YAML which includes symbols and various representations which will be helpful while converting or processing them in JSON format. These attributes are also called as key names in JSON documents. These notations are created for security purposes.
The above YAML format represents various attributes of defaults, adapter, and host with various other attributes. YAML also keeps a log of every file generated which maintains a track of error messages generated. On converting the specified YAML file in JSON format we get a desired output as mentioned below −
defaults: &defaults adapter: postgres host: localhost development: database: myapp_development <<: *defaults test: database: myapp_test <<: *defaults
Let’s convert the YAML to JSON format and check on the output.
{ "defaults": { "adapter": "postgres", "host": "localhost" }, "development": { "database": "myapp_development", "adapter": "postgres", "host": "localhost" }, "test": { "database": "myapp_test", "adapter": "postgres", "host": "localhost" } }
The defaults key with a prefix of “ <<: *” is included as and when required with no need to write the same code snippet repeatedly.