Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax #12

Open
Taddic opened this issue Oct 24, 2013 · 1 comment
Open

Syntax #12

Taddic opened this issue Oct 24, 2013 · 1 comment
Labels

Comments

@Taddic
Copy link

Taddic commented Oct 24, 2013

Hi Alavrik,

I would like to use your library for a project. I have looked through your code and tested it and I like it overall. I have one small problem though, I haven't been able to figure out how to make this type of query:
"attr1[0].attr2" but using your notation.
Does your library support to make such queries?

What I would like to be able to do is the following:
Search for or replace a value at let's say position "attr1[0].attr2" in for instance this json object: {attr1 : [{attr2 : value1}, {attr2 : value2}]}

In a more erlang fashion it would be like this.

A = erlson:from_json("{\"attr1\":[{\"attr2\":\"value1\"},{\"attr2\":\"value1\"}]}").
Search = [attr1, 0, attr2].
erlson:store(Search, <<"new_value1">>, A).

and similarly for erlang erlson:get_value/2, where it would just return "value1"

Keep up the good work :)
Cheers,
/Tommy

@alavrik
Copy link
Owner

alavrik commented Dec 8, 2013

Hi Tommy, I'm so sorry! Somehow I missed your message.

When creating Erlson, I didn't want to step too far from Erlang syntax and tried to add as little changes as possible. Syntax support I've added so far generally follow Erlang semantics. Adding syntax for list element access would mean introducing a new operation that's not present in Erlang. I'd prefer to avoid that.

On the other hand, adding the ability to address individual list elements in the erlson:store() and erlson:get_value() may be useful.

The only thing I'm worried about is that setting list element by its integer position is not really a functional interface. Naturally, you won't find such functions in the lists module. In theory, we could restrict the set operation to be applicable to only those integer indexes that are already present in the list, but it may lead to even more confusion as it would be clearly more restrictive compared to setting/adding dictionary elements by name.

Now, if for these reasons we rule out the API for setting list elements by an int, should we event bother extending get_value to support getting list elements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants