Design
Array manipulation
List of function to manipulate and transform your JSON arrays
COMMUNITY FEATURE
Available for:
Carbone Cloud
Carbone On-premise
Embedded Carbone JS
v2.0+
:arrayJoin(separator, index, count)
NEW v4.12.0+
Flatten an array of String or Number
Params | Description | Type |
---|---|---|
separator | [optional] item separator (, by default) |
String |
index | [optional] select items from this array index. | Number |
count | [optional] number of items to select from index . count can be a negative number to select N items from the end of the array. |
Number |
Examples
['homer','bart','lisa']:arrayJoin() // "homer, bart, lisa"
['homer','bart','lisa']:arrayJoin(' | ') // "homer | bart | lisa"
['homer','bart','lisa']:arrayJoin('') // "homerbartlisa"
[10,50]:arrayJoin() // "10, 50"
[]:arrayJoin() // ""
null:arrayJoin() // null
{}:arrayJoin() // {}
20:arrayJoin() // 20
undefined:arrayJoin() // undefined
['homer','bart','lisa']:arrayJoin('', 1) // "bartlisa"
['homer','bart','lisa']:arrayJoin('', 1, 1) // "bart"
['homer','bart','lisa']:arrayJoin('', 1, 2) // "bartlisa"
['homer','bart','lisa']:arrayJoin('', 0, -1) // "homerbart"
:arrayMap(objSeparator, attSeparator, attributes)
v0.12.5+
Flatten an array of objects
It ignores nested objects and arrays. If you want to access nested objects, use aggStr
instead.
Params | Description | Type |
---|---|---|
objSeparator | [optional] object separator (, by default) |
String |
attSeparator | [optional] attribute separator (: by default) |
String |
attributes | [optional] list of object's attributes to print | String |
Examples
[{'id':2,'name':'homer'},{'id':3,'name':'bart'}]:arrayMap() // "2:homer, 3:bart"
[{'id':2,'name':'homer'},{'id':3,'name':'bart'}]:arrayMap(' - ') // "2:homer - 3:bart"
[{'id':2,'name':'homer'},{'id':3,'name':'bart'}]:arrayMap(' ; ', '|') // "2|homer ; 3|bart"
[{'id':2,'name':'homer'},{'id':3,'name':'bart'}]:arrayMap(' ; ', '|', 'id') // "2 ; 3"
[{'id':2,'name':'homer','obj':{'id':20},'arr':[12,23]}]:arrayMap() // "2:homer"
['homer','bart','lisa']:arrayMap() // "homer, bart, lisa"
[10,50]:arrayMap() // "10, 50"
[]:arrayMap() // ""
null:arrayMap() // null
{}:arrayMap() // {}
20:arrayMap() // 20
undefined:arrayMap() // undefined
:count(start)
v1.1.0+
Count and print row number of any array
Usage example: d[i].id:count()
will print a counter of the current row no matter the value of id
This formatter is replaced internally by :cumCount
since version v4.0.0
Params | Description | Type |
---|---|---|
start | Number to start with (default: 1) | String |