0

I want to implement a function that takes an json as argument as well as an access formula which describes the path to a property.

public String accessJsonDynamically(JSONObject json, String formula) {
    //
}

For example the a[0].b.prop1 along with the example json should return foo.

 {
    "a": [{
        "b": {
            "prop1": "foo",
            "prop2": "bar"
        }
    }, {
        "c": {
            "prop1": "bar"
        }
    }],
    "d": 3
}
PKuhn
  • 1,338
  • 1
  • 14
  • 30

1 Answers1

1

That dynamic formula is otherwise known as a 'JSONPath' - see this existing Q&A on the matter.

M.

Martin Cowie
  • 2,788
  • 7
  • 38
  • 74