Marshal

Index

All Marshal functions

Name Function header Example Result Description Errorhandling
marshal func(v interface{}) string [[ $result := marshal "This is a test string" ]] $result = “\“This is a test string\“”` converts an GO object to a JSON object
marshalIndent func(v interface{}) string [[ $result := marshalIndent $data ]]
check code example to create the $data object
$result = “{\n \“teststring\”: [\n \“This\“,\n \“is\“,\n \“a\“,\n \“Test String\”\n ]\n}”` indent the object with 2 additional positions per JSON level.
marshalJson func(v interface{}) string [[ $result := marshal "This is a test string" ]] $result = “\“This is a test string\“”` converts an GO object to a JSON object
marshalJsonIndent func(v interface{}) string [[ $result := marshalIndent $data ]]
check code example to create the $data object
$result = “{\n \“teststring\”: [\n \“This\“,\n \“is\“,\n \“a\“,\n \“Test String\”\n ]\n}”` indent the object with 2 additional positions per JSON level.
marshalYaml func(data interface{}) string [[ $result := marshalYaml $data ]]
check code example to create the $data object
$result = “teststring:\n- This\n- is\n- a\n- Test String\n” converts an object to a YAML object
toJson func(v interface{}) string [[ $result := marshal "This is a test string" ]] $result = “\“This is a test string\“”` converts an GO object to a JSON object
toPrettyJson func(v interface{}) string [[ $result := marshalIndent $data ]]
check code example to create the $data object
$result = “{\n \“teststring\”: [\n \“This\“,\n \“is\“,\n \“a\“,\n \“Test String\”\n ]\n}”` indent the object with 2 additional positions per JSON level.
unmarshal (still in development) func(source string) (data interface{}) [[ $v := unmarshal "['abc', 'cde']" ]] $v contains a new object depends on the input. in this case its a array
unmarshalYaml (still in development) func(source string) (data interface{}) [[ $v := unmarshalYaml $myyamlstring ]] $v contains a new object depends on the input

marshal

func(v interface{}) string

The marshal function converts an GO object to a JSON object.

The Go standard library offers a package that has all you need to perform JSON encoding and decoding. It allows you to do encoding of JSON data as defined in the RFC 7159. When working with data we usually want to encode some Go struct into a json string. However the Go standard library encoding/json package allows us to encode any data type into a JSON string.

Application notes / Limits:

In ingrid functions we work with flat JSON objects. So the handling is very easy. If you need to convert complex JSON structures, please check the ingrid service js interceptor

Examples


JSON Marshal String
[[ $result := marshal "This is a test string" ]]
$result = "\"This is a test string\""

JSON Marshal Int
[[ $result := marshal (int "28192") ]]
$result = 28192

JSON Marshal Bool
[[ $result := marshal (true) ]]
$result = true

Combination Marshal with other ingrid-functions
ingrid: getCurrentRequest: Result contains only the beginning of the result, to get an idea.
[[ $result := marshal getCurrentRequest ]]
$result = "{\"ID\":\"6cc67de5-c627-448d....*"

ingrid: getCurrentRequest: Test to console
[[ noescape ( marshal getCurrentRequest ) ]]
$result = "{\"ID\":\"6cc67de5-c627-448d....*"

ingrid: getCurrentResult: Result contains only beginning of the result, to get an idea.
[[ $result := marshal getCurreResult ]]
$result = "{\"Code\":200,\"Message\":\"Success\",\"Control\":{},\"Data\":{\"Do...*"

ingrid: combination of ingrid functions
[[ setCurrentControl newControl ]]
[[ setCurrentControlValue "Testcontrol" "Go1 On" ]]
[[ addCurrentControlValue "Testcontrol" "Go2 On" ]]
[[ addCurrentControlValue "Testcontrol" "Go3 On" ]]
[[ $result := marshal getCurrentControl ]]
$result = "[\"Go1 On\",\"Go2 On\",\"Go3 On\"]"

ingrid: removeCurrentControlValue based on the previous combination code block
[[ removeCurrentControlValue "Testcontrol" "Go2 On" ]]
[[ $result := marshal getCurrentControl ]]
$result = "[\"Go1 On\",\"Go3 On\"]"

marshalIndent

func(v interface{}) string

The marshalIndent function indent the object with 2 additional positions per JSON level.

Application notes / Limits:

  • the functions needs an object as input. If you insert e.g. a string or an integer, there won’t be some indent for this object.

Examples


Object is a data object. So indent will work
[[ $data := newData ]]
[[ $data = setValue $data "teststring" "This" ]]
[[ $data = addValue $data "teststring" "is" ]]
[[ $data = addValue $data "teststring" "a" ]]
[[ $data = addValue $data "teststring" "Test String" ]]
[[ $result := marshalIndent $data ]]
$result = "{\n  \"teststring\": [\n    \"This\",\n    \"is\",\n    \"a\",\n    \"Test String\"\n  ]\n}"

marshalJsonIndent

see function description marshalIndent

marshalYaml

func(data interface{}) string

The marshalYaml function converts an object to a YAML object

Application notes / Limits:

Examples


[[ $data := newData ]]
[[ $data = setValue $data "teststring" "This" ]]
[[ $data = addValue $data "teststring" "is" ]]
[[ $data = addValue $data "teststring" "a" ]]
[[ $data = addValue $data "teststring" "Test String" ]]
[[ $result := marshalYaml $data ]]
$result = "teststring:\n- This\n- is\n- a\n- Test String\n"

toJson

see function description marshal

toPrettyJson

see function description marshalIndent

unmarshal

// TODO: function not finished. Additional it should convert or abstract the result data interface

func(source string) (data interface{})

The unmarshal function …

Application notes / Limits:

Examples


Example does not run at the moment. See TODO in this function definition
unmarshal
[[ $result := unmarshal "[\"abc\", \"cde\"]" ]]
[[ range $v := $result ]]
  [[ addCurrentResultDataValue "DocuFixValue10" $v ]]
[[ end ]]

[[ $result ]]

unmarshalYaml

// TODO: function not finished. Additional it should convert or abstract the result data interface

func(source string) (data interface{})

The unmarshalYaml function …

Application notes / Limits:

Examples