Browse the docs

parseFields

Reads Key: value lines or key=value&… into one record.

Details #

parseFields(text) reads Key: value lines such as email headers or log lines, key = value lines, or one key=value&key=value query string (percent-decoded, + as a space). It returns one record. A key that appears more than once becomes a list of its values in order.

A line that starts with a space or tab continues the one above it, as folded email headers do. Blank lines and lines starting with # are skipped.

Parameters #

Takes 1 argument. {{ parseFields(text) }}

Examples #

parseFields("From: Ann\nSubject: Hello")
→ { "From" : "Ann", "Subject" : "Hello" }
parseFields("a=1&b=two%20words&a=3").a
→ [ "1", "3" ]

Gotchas #

  • Values are always text. The key is whatever comes before the first : or = on the line.

  • Text with no key lines in it fails with parseFields() couldn't find.