JSON arithmetic evaluator issue

Viewed 48

I am trying to add new fields based on available fields in JSON using library: Golang expr. But not working as expected.

Is there any way to perform add/remove/replace operations on JSON field with arithmetic operations?

Example:

{
 "field1":1,
 "field2":2,
}

Operation: add; 
field3 = (field1 + field2)
field4 = (field1 * field2 * field3)/4
field5 = (field4 > 1)

Result:
{
  "field1":1,
  "field2":2,
  "field3":3,
  "field4":1.5,
  "field5": true
}
0 Answers
Related