How to traverse and manipulate json decoder

sorry if it is beginner level but this bothers me overnight. I’ve got a task about writing about lib for manipulating json file with defined configuration file.
e.g:

[
    {
        "age": 65,
        "income": 6000,
    }
]

example configuration file (define path and many operation with the fields)

"income","arithmetic","multiply","0.8"

and the result is a new output json file with changed fields (may be with more complicated objects, map, array, etc):

[
    {
        "age": 65,
        "income": 4800,
    }
]

Since the json file is arbitrary, I found there’s no way to decode and encode with pre-defined structs by encoding/json lib.
Any ideas on how to solve this correctly? appreciate it.

Unless you can define allowable fields, it’ll be easiest to decode into a map. You might be able to use custom unmarshalling to decode into a struct that contains age and income fields and put the arbitrary fields in a map. I haven’t done that, so I’d just go with built-in decoding into a map.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.