The Encodian population engine provides features to perform common manipulations on a collection (Iterable). These features mimic the extension methods provided by IEnumerable<T>, thus, you can group, sort, and perform other sequential data manipulations in template expressions in a common way.
In the below examples, the term persons refers to the data collection (array, list, or enumerable) that the method operates on. It’s simply a placeholder for any collection you might have in your JSON data.
| Extension Method | Example |
| All(Predicate) |
Check if all elements in a collection satisfy a specified condition. persons.All(p => p.Age < 50) This can be used on it's own and will return either true or false or as part of an IF statement <<[persons.All(p => p.Age < 50)]>> Or <<if [persons.All(p => p.Age < 50)]>>Everyone is younger than 50. <</if>> |
| Any() | |
| Any(Predicate) |
Checks if any element in a collection satisfies a specified condition. It returns
Example:
|
| Average(Selector) |
Calculate the mean value of a numeric property across all items in. a collection.
|
| Concat(IEnumerable) | |
| Contains(Object) |
Check if a key value or collection contains an item that matches a specified condition.
------------- Example template syntax
Example JSON:
Word document result:
Expanding on the example above you can change the syntax slightly to find everything that doesn't match the condition.
Word document result:
|
| Count() |
Count the amount of elements in the array persons.Count() Example template syntax <<[Persons.Count()]>> Example JSON {
"Persons": [
{"name": "Oakley", "age": 18},
{"name": "Carter", "age": 32},
{"name": "Declan", "age": 35},
{"name": "Brody", "age": 13}
]}
Result 4 |
| Count(Predicate) |
Count the elements in an array fulfilling a criteria persons.Count(p => p.Age > 30) Example template syntax <<[Persons.Count(p => p.age > 30)]>> Example JSON {
"Persons": [
{"name": "Oakley", "age": 18},
{"name": "Carter", "age": 32},
{"name": "Declan", "age": 35},
{"name": "Brody", "age": 13}
]}
Result 2 |
| Distinct() | |
| ElementAt() |
Returns the element at the given location in the array ElementAt() Example template syntax <<[(Numbers.ElementAt(2))["number"]]>> Example JSON {
"Numbers": [
{"number": 10},
{"number": 2},
{"number": 13},
{"number": 40}
]
}
Word document result: 13 |
| First() | |
| First(Predicate) | |
| FirstOrDefault() | |
| FirstOrDefault(Predicate) | |
| GroupBy(Selector) |
Group items in a collection based on a specified property or key.
or
------------- Example template syntax:
Example JSON:
Word document result:
|
| Last() | |
| Last(Predicate) | |
| LastOrDefault() | |
| LastOrDefault(Predicate) | |
| Max(ComparableSelector) | |
| Min(ComparableSelector) | |
| OrderBy(ComparableSelector) |
Or
|
| OrderByDescending(ComparableSelector) |
Or
|
| Select(Selector) | |
| SelectMany(EnumerationSelector) | |
| Single() | |
| Single(Predicate) | |
| SingleOrDefault() | |
| SingleOrDefault(Predicate) | |
| Skip(int) | |
| SkipWhile(Predicate) | |
| Sum(Selector) | |
| Take(int) | |
| TakeWhile(Predicate) | |
| Union(IEnumerable) | |
| Where(Predicate) | |
Syntax Support
Please refer to our Template Design forum where our support team can help with template syntax / you can see solutions to common use cases.
0 Comments