Reputation: 359
How can I transform a specific item in an array to integer? In the following example, I want only the 3rd element 456
to be converted to integer, and 123
to be left intact:
input:
{
"arr": [
"hello",
"123",
"456"
]
}
Trying this spec:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"arr": "=toInteger"
}
}
]
I get actual output:
{
"arr": [
"hello",
123,
456
]
}
However, the desired output should look like this: expected output:
{
"arr": [
"hello",
"123",
456
]
}
Thank you, Gerasimos
Upvotes: 1
Views: 1876
Reputation: 65323
You should get
{
"arr": [
"hello",
123,
456
]
}
for the current case. Just need to restrict to the index(2
) of the desired element within the spec such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"arr": {
"[2]": "=toInteger"
}
}
}
]
in order to get the desired result, that's :
{
"arr": [
"hello",
"123",
456
]
}
Upvotes: 0