[getdns-api] Getting from dicts by subscript operator

Shane Kerr shane at time-travellers.org
Wed Sep 23 15:37:25 CEST 2015


Joe,

So I guess that you propose that instead of:

"replies_tree[0][header][ad]" 

We would use:

"replies_tree[0]/header/ad"

Or:

"replies_tree/0/header/ad"

I think that the last one is "correct" JSON Pointer syntax if I
understand the RFC, but I confess that the one above it looks easier to
read to me. :)

--
Shane

On Mon, 21 Sep 2015 18:09:11 +0000
"Joe Hildebrand (jhildebr)" <jhildebr at cisco.com> wrote:

> Please don't invent a new syntax.  Use RFC 6901.
> 
> http://tools.ietf.org/html/rfc6901
> 
> 
> -- 
> Joe Hildebrand
> 
> 
> 
> 
> 
> 
> 
> On 9/21/15, 11:54 AM, "spec on behalf of Goyal, Neel" <spec-bounces at getdnsapi.net on behalf of ngoyal at verisign.com> wrote:
> 
> >I like it - however I¹d suggest tweaking the syntax a bit:
> >
> >"replies_tree[0][header][ad]² would become "replies_tree[0].header.ad²
> >
> >
> >So the bracket syntax indicates that it¹s an array index and then the dot
> >specifier indicates it¹s a field within a dict.
> >
> >
> >On 9/21/15, 12:26 PM, "spec on behalf of Wessels, Duane"
> ><spec-bounces at getdnsapi.net on behalf of dwessels at verisign.com> wrote:
> >
> >>Willem,
> >>
> >>I think this idea is really great!
> >>
> >>
> >>> On Sep 18, 2015, at 2:13 AM, Willem Toorop <Willem at nlnetlabs.nl> wrote:
> >>> 
> >>> Dear getdns API designers,
> >>> 
> >>> Getting into the specific parts of getdns data structures (notably the
> >>> response dict) can be cumbersome in C.  Take for example this
> >>> (relatively short) example on how to get to the AD bit of the first
> >>> reply of a response:
> >>> 
> >>> getdns_list *replies_tree;
> >>> getdns_dict *reply;
> >>> getdns_dict *header;
> >>> uint32_t     ad;
> >>> 
> >>> if ((r = getdns_dict_get_list(resp, "replies_tree", &replies_tree)))
> >>> 	return r;
> >>> else if ((r = getdns_list_get_dict(replies_tree, 0, &reply)))
> >>> 	return r;
> >>> else if ((r = getdns_dict_get_dict(reply, "header", &header)))
> >>> 	return r;
> >>> else if ((r = getdns_dict_get_int(header, "ad", &ad)))
> >>> 	return r;
> >>> 
> >>> 
> >>> Also, getting data members by text strings like getdns does, is
> >>> unconventional in C libraries, but makes getdns very flexible and easy
> >>> to extend.  It also maps very well to modern scripting languages
> >>> (python, javascript, perl, ruby etc.).
> >>> 
> >>> Why don't we take this approach one step further, and get to the data
> >>> members by allowing the text strings to contain subscript operators into
> >>> the sub-dicts and sub-lists?
> >>> 
> >>> To do the same as the example above with subscript operator:
> >>> 
> >>> uint32_t ad;
> >>> 
> >>> if ((r = getdns_dict_get_int(resp, "replies_tree[0][header][ad]", &ad)))
> >>> 	return r;
> >>> 
> >>> The conciseness and thereby clarity and readability is increasingly more
> >>> prominent with more involved examples.
> >>> 
> >>> 
> >>> What do you think?
> >>> 
> >>> -- Willem
> >>> _______________________________________________
> >>> spec mailing list
> >>> spec at getdnsapi.net
> >>
> >
> >
> >_______________________________________________
> >spec mailing list
> >spec at getdnsapi.net
> 
> _______________________________________________
> spec mailing list
> spec at getdnsapi.net



More information about the spec mailing list