rapidpro / expressions

Expression parsing and evaluation support
BSD 3-Clause "New" or "Revised" License
4 stars 4 forks source link

How to get data from Array #26

Closed javierpe closed 6 years ago

javierpe commented 6 years ago

Example: contact.put("groups", Arrays.asList("Testers", "Developers")); I getting an error: context.resolveVariable("contact.groups.something");

Help me please!

rowanseymour commented 6 years ago

@FranciscoJavierPRamos could you provide some more information about what you're trying to do.

javierpe commented 6 years ago

I have this code: `

    Map<String, Object> contact = new HashMap<>();
    contact.put("*", "Bob");
    contact.put("name", "Bob");
    contact.put("age", 33);
    contact.put("join_date_1", "28-08-2015 13:06");
    contact.put("isnull", null);
    contact.put("isbool", true);
    contact.put("isfloat", 1.5f);
    contact.put("islong", 9223372036854775807L);
    contact.put("isdict", dict);

    Map<String, Object> address1 = new HashMap<>();
    address1.put("country", "México");
    address1.put("city", "Puebla");

    Map<String, Object> address2 = new HashMap<>();
    address2.put("country", "España");
    address2.put("city", "Barcelona");

    contact.put("address", Arrays.asList(address1, address2));

`

Im trying to get data some like this: contact.address[0].country

rowanseymour commented 6 years ago

Ah ok. This expressions library doesn't support array indexing. However we're in the process of developing a new engine which will: https://github.com/nyaruka/goflow

javierpe commented 6 years ago

Thank you!

rowanseymour commented 6 years ago

Sorry @nicpottier just reminded me you should be able to do contact.address.0.country!

In the new goflow engine you'll be able to write [0]

javierpe commented 6 years ago

contact.address.0.country does not work for me :(