DESIGN SYSTEM

  • Principles
  • Components
  • Documentation
FUNCTIONS

transform.Unmarshal

transform.Unmarshal (alias unmarshal) parses the input and converts it into a map or an array. Supported formats are JSON, TOML, YAML and CSV.

Syntax

RESOURCE or STRING | transform.Unmarshal [OPTIONS]

The function accept either a Resource created in Hugo Pipes or via Page Bundles, or simply a string. The two examples below will produce the same map:

{{ $greetings := "hello = \"Hello Hugo\"" | transform.Unmarshal }}`
{{ $greetings := "hello = \"Hello Hugo\"" | resources.FromString "data/greetings.toml" | transform.Unmarshal }}

In both the above examples, you get a map you can work with:

{{ $greetings.hello }}

The above prints Hello Hugo.

CSV Options

Unmarshal with CSV as input has some options you can set:

delimiter
The delimiter used, default is ,.
comment
The comment character used in the CSV. If set, lines beginning with the comment character without preceding whitespace are ignored.:

Example:

{{ $csv := "a;b;c" | transform.Unmarshal (dict "delimiter" ";") }}
  • Foundation styles (FS)
  • Content text (CT)
  • Buttons and links (BL)
  • Form elements (FE)
  • Icons (IC)
  • Miscellaneous (MS)
“transform.Unmarshal” was last updated: January 29, 2019: A little bit of naming reorganisation (8fb631a0)
Improve this page
By the Hugo Authors
Hugo Logo
  • File an Issue
  • Get Help
  • Discuss Source Code
  • @GoHugoIO
  • @spf13
  • @bepsays

 
  Hugo Sponsors
Logo for Forestry.io
Logo for Linode
Logo for eSolia
 

The Hugo logos are copyright © Steve Francia 2013–2019.

The Hugo Gopher is based on an original work by Renée French.

  • Principles
  • Components
  • Documentation
  • Foundation styles (FS)
  • Content text (CT)
  • Buttons and links (BL)
  • Form elements (FE)
  • Icons (IC)
  • Miscellaneous (MS)