Got {"a": 1, "b": 2, "c": 3}
want it be {"a": 1, "b": 6, "c": 3}
but if I {"a": 1, "b": 2, "c": 3} * {"b": 3}
it ends up {"a": 1, "b": 3, "c": 3}
.
How do I make it happen with jq?
Got {"a": 1, "b": 2, "c": 3}
want it be {"a": 1, "b": 6, "c": 3}
but if I {"a": 1, "b": 2, "c": 3} * {"b": 3}
it ends up {"a": 1, "b": 3, "c": 3}
.
How do I make it happen with jq?
If you want to multiply the .b value in an object by 3, you could write:
.b *= 3
If you want to define a multiplication operation on JSON objects, consider:
def multiply(o):
reduce (o|keys_unsorted[]) as $k (.; .[$k] *= o[$k]);
Using your example:
{"a": 1, "b": 2, "c": 3} | multiply({"b":3})
yields:
{
"a": 1,
"b": 6,
"c": 3
}