[erlang-questions] Querying JSON, team chat
Seth Falcon
seth@REDACTED
Sun Apr 7 17:58:09 CEST 2013
(hope you don't mind that I put this back on the list)
On Sat, Apr 6, 2013 at 11:04 PM, Andrei Soroker <soroker@REDACTED> wrote:
> Whoa, I had no idea ej existed! Why did you pick a tuple vs. a list for
> the path?
>
To be honest, I don't think this was a very good design choice on my part
and I would go with a list if I was starting over. I wanted to be able to
support accessing array elements by index and if I'm remembering my thought
process, I was worried about the ambiguity of passing a bare string
accidentally instead of a list. In ej, you can do:
J = [<<"a1">>, <<"a2">>, <<"a3">>].
ej:get({2}, J).
<<"a2">>
If the path argument was a list, and bare integers were still the way to
ask for an array element by index, then the code would allow you to say
this:
ej:get("accident", J)
That would probably end up failing anyway, just not straight away. Given
how infrequently I've ended up with a need for array access by index, I
think a better choice would have been to stick with list for the path and
then tag indices like {idx, 5}.
> I am also somewhat partial to the analogy with XPath, which only addresses
> reading and not writing.
>
Horses for courses :) We end up using the set and delete quite a bit for
normalizing incoming data before validating with ej:valid.
+ seth
--
Seth Falcon | @sfalcon | http://userprimary.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130407/c0f44119/attachment.htm>
More information about the erlang-questions
mailing list