split
Splits a string into a list at every separator. The separator is a non-empty string, not a regular expression.
rules
input
Validoutput
{
"ids": [
1,
2,
3
]
}js
{ ids: [{ split: ',' }, { list_of: 'positive_integer' }] }It is a modifier, so it never fails:
- A string is split at every separator:
"1,2,3"gives["1", "2", "3"],"5"gives["5"]. Empty parts are kept:"a,,b"gives["a", "", "b"]. - A list stays as it is, so
?id=5&id=6and?ids=5,6both give a list. - A number or a boolean is split in its string form, like a string:
5gives["5"],1.5with"."gives["1", "5"],truegives["true"]. - An empty value and an object stay as they are; the next rule reports them.
This also covers inputs from query strings that can be a scalar or a list.