'jsonpath multiplication operation over entire object
I have an object of the basic structure:
[
{
"a": 1,
"b": 1,
"c": 1
},
{
"a": 2,
"b": 2,
"c": 2
},
{
"a": 3,
"b": 3,
"c": 3
}
]
All I need to do is programmatically multiply all the key values by x
while keeping the structure exactly intact.
Example: if x=10
then the result would be:
[
{
"a": 10,
"b": 10,
"c": 10
},
{
"a": 20,
"b": 20,
"c": 20
},
{
"a": 30,
"b": 30,
"c": 30
}
]
I would presume that jsonpath is the way to do this, but I cannot figure out the proper query and the (postgres) documentation is very sparse on these details though it clearly implies that this can be done.
Solution 1:[1]
JSONPath is intended for filtering input JSON tree, not for JSON transformations. It is literally an expression to guide processor to the elements of JSON to be picked for the output. The values in the original JSON or their aggregates can used to make filtering decisions, however, the output values are the unmodified source values. It is not possible to even reshape the JSON. It is possible however, to pick branches and leaves form the original tree that match filter criteria.
Consider using JQ instead
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Delta George |