murex Shell Docs

API Reference: Unmarshal()

Converts a structured file format into structured memory


This is a function you would write when programming a murex data-type. The unmarshal function takes in a byte slice and returns a Go (golang) type or struct or an error.

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


Registering unmarshal (for writing builtin data-types)

// To avoid data races, this should only happen inside func init()
lang.Unmarshallers["json"] = unmarshal

Using an existing unmarshaller (eg inside a builtin command)

// See documentation on lang.UnmarshalData for more details
v, err := lang.UnmarshalData(p *lang.Process, dataType string)


Defining a marshaller for a murex data-type

package example

import (


func init() {
    // Register data-type
    lang.Unmarshallers["example"] = unmarshal

// Describe unmarshaller
func unmarshal(p *lang.Process) (interface{}, error) {
    // Read data from STDIN. Because JSON expects closing tokens, we should
    // read the entire stream before unmarshalling it. For formats like CSV or
    // jsonlines which are more line based, we might want to read STDIN line by
    // line. However given there is just one data return, you still effectively
    // head to read the entire file before returning the structure. There are
    // other APIs for iterative returns for streaming data - more akin to the
    // traditional way UNIX pipes would work.
    b, err := p.Stdin.ReadAll()
    if err != nil {
        return nil, err

    var v interface{}
    err = json.Unmarshal(b, &v)

    // Return the Go data structure or error
    return v, err


  1. *lang.Process: Process's runtime state. Typically expressed as the variable p

See Also

This site is rebuilt weekly, the content is automatically generated from murex's source code. Last built on Mon Oct 19 06:12:17 UTC 2020 against commit 81299cb81299cbf18c05a5d38bdde93a5f5a3c5ff005b27. Downloadable murex binaries are also built weekly. Current version is 1.0.0000 BETA which has been verified against tests.