murex Shell Docs

API Reference: Marshal() (type)

Converts structured memory into a structured file format (eg for stdio)


This is a function you would write when programming a murex data-type. The marshal function takes in a Go (golang) type or struct and returns a byte slice of a “string” representation of that format (eg in JSON) or an error.

This marshaller is then registered to murex inside an init() function and murex builtins can use that marshaller via the MarshalData() API.


Registering Marshal() (for writing builtin data-types)

// To avoid data races, this should only happen inside func init()
lang.Marshallers[ /* your type name */ ] = /* your readIndex func */

Using an existing marshaller (eg inside a builtin command)

// See documentation on lang.MarshalData for more details
b, err := lang.MarshalData(p, dataType, data)


Defining a marshaller for a murex data-type

package example

import (


func init() {
    // Register data-type
    lang.Marshallers["json"] = marshal

// Describe marshaller
func marshal(p *lang.Process, v interface{}) ([]byte, error) {
    if p.Stdout.IsTTY() {
        // If STDOUT is a TTY (ie not pipe, text file or other destination other
        // than a terminal) then output JSON in an indented, human readable,
        // format....
        return json.MarshalIndent(v, "", "    ")

    // ....otherwise we might as well output it in a minified format
    return json.Marshal(v)


  1. *lang.Process: Process’s runtime state. Typically expressed as the variable p
  2. interface{}: data you wish to marshal

See Also

This site's content is rebuilt automatically from murex's source code after each merge to the master branch. Downloadable murex binaries are also built with the website.

Last built on Thu Oct 13 08:08:18 UTC 2022 against commit ed6b6fced6b6fc609f4be93c5d3348695a762facfecf48f.

Current version is 2.11.2200 which has been verified against 16798 tests cases.