Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(vrl): Add documentation for new object_from_array function #21969

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions website/cue/reference/remap/functions/object_from_array.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package metadata

remap: functions: object_from_array: {
category: "Object"
description: """
Iterate over either one or a pair of arrays and create an object out of all the key, value pairs contained in them.
bruceg marked this conversation as resolved.
Show resolved Hide resolved
Any entries that are missing the value will use `null` instead.
bruceg marked this conversation as resolved.
Show resolved Hide resolved
Any keys that are `null` will skip the corresponding value.
bruceg marked this conversation as resolved.
Show resolved Hide resolved

If a single parameter is given, it must contain an array of all the input arrays.
"""

arguments: [
{
name: "values"
description: "The first array of elements, or the array of input arrays if no other parameter is present."
required: true
type: ["array"]
},
{
name: "keys"
description: "The second array of elements. If not present, the first parameter contains all the arrays."
bruceg marked this conversation as resolved.
Show resolved Hide resolved
required: false
type: ["array"]
},
]
internal_failure_reasons: [
"`values` and `keys` must be arrays.",
"If `keys` is not present, `values` must contain only arrays.",
]
return: {
types: ["object"]
rules: [
"`object_from_array` is considered fallible if either of the parameters is not an array, or if only the `value` parameter is present and it is not an array of arrays, or if any of the keys are not either a string or `null`.",
bruceg marked this conversation as resolved.
Show resolved Hide resolved
]
}

examples: [
{
title: "Create an object from one array"
source: #"""
object_from_array([["one", 1], [null, 2], ["two", 3]])
"""#
return: {"one": 1, "two": 3}
},
{
title: "Create an object from separate key and value arrays"
source: #"""
object_from_array([1, 2, 3], keys: ["one", null, "two"])
"""#
return: {"one": 1, "two": 3}
},
]
}
2 changes: 1 addition & 1 deletion website/cue/reference/remap/functions/zip.cue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ remap: functions: zip: {
return: {
types: ["array"]
rules: [
"`zip` is considered fallible if any of the parameters is not an array, or if only the first parameter is present and it is not an array of arrays.",
"`zip` is considered fallible if either of the parameters is not an array, or if only the first parameter is present and it is not an array of arrays.",
bruceg marked this conversation as resolved.
Show resolved Hide resolved
]
}

Expand Down
Loading