Ten days ago, I made my first REST queries using the shell.
Two days later, I tried the same queries with J. This turned out to be quite easy because two addons do all the work:
require 'web/gethttp convert/json'
j =. gethttp 'https://atlas.ripe.net/api/v2/probes/2871'
_60 ]\ j
{"prefix_v4":"217.13.64.0/20","status":{"since":"2018-06-13T
04:35:32Z","id":1,"name":"Connected"},"prefix_v6":"2a00:1030
::/32","description":"GDS Marshlabs","last_connected":152912
2097,"tags":[{"name":"DSL","slug":"dsl"},{"name":"Home","slu
g":"home"},{"name":"No NAT","slug":"no-nat"},{"name":"IPv6 T
unnel","slug":"ipv6-tunnel"},{"name":"dual-stack","slug":"du
al-stack"},{"name":"IPv4","slug":"ipv4"},{"name":"IPv6","slu
g":"ipv6"},{"name":"system: V2","slug":"system-v2"},{"name":
"system: Resolver Mangles Case","slug":"system-resolver-mang
les-case"},{"name":"system: IPv4 Works","slug":"system-ipv4-
works"},{"name":"system: IPv6 Works","slug":"system-ipv6-wor
ks"},{"name":"Native IPv4","slug":"native-ipv4"},{"name":"sy
stem: IPv4 Capable","slug":"system-ipv4-capable"},{"name":"s
ystem: IPv6 Capable","slug":"system-ipv6-capable"},{"name":"
system: IPv6 Stable 1d","slug":"system-ipv6-stable-1d"},{"na
me":"system: IPv4 Stable 1d","slug":"system-ipv4-stable-1d"}
],"geometry":{"type":"Point","coordinates":[10.5215,52.2675]
},"type":"Probe","address_v6":"2a00:1030:100:0:220:4aff:fee0
:2212","address_v4":"217.13.64.149","total_uptime":190721773
,"country_code":"DE","is_public":true,"id":2781,"asn_v4":249
56,"asn_v6":24956,"status_since":1528864532,"first_connected
":1333468450,"is_anchor":false}
_ 3 {. dec_json j
┌──────────────┬───────────────────────────────────┬──────────────┐
│prefix_v4 │status │prefix_v6 │
├──────────────┼───────────────────────────────────┼──────────────┤
│217.13.64.0/20│┌────────────────────┬──┬─────────┐│2a00:1030::/32│
│ ││since │id│name ││ │
│ │├────────────────────┼──┼─────────┤│ │
│ ││2018-06-13T04:35:32Z│1 │Connected││ │
│ │└────────────────────┴──┴─────────┘│ │
└──────────────┴───────────────────────────────────┴──────────────┘
So the json decoder turns syntactical markup into equivalent nested boxed data in the J world.
The J primitives dealing with such nested boxes are
L.
Level OfL:
Level At{::
Map/FetchS:
SpreadTime to dig deeper into these. I spent a few hours until I really understood why, for example,
|. L:1 ] _ 3 {. dec_json j
┌──────────────┬───────────────────────────────────┬──────────────┐
│4v_xiferp │sutats │6v_xiferp │
├──────────────┼───────────────────────────────────┼──────────────┤
│02/0.46.31.712│┌────────────────────┬──┬─────────┐│23/::0301:00a2│
│ ││2018-06-13T04:35:32Z│1 │Connected││ │
│ │├────────────────────┼──┼─────────┤│ │
│ ││since │id│name ││ │
│ │└────────────────────┴──┴─────────┘│ │
└──────────────┴───────────────────────────────────┴──────────────┘
As of now, I am missing the flexibility of the {
From selectors with the very rigid {::
Fetch paths.
Some blend would be nice.
Also, I am still marvelling at possibilities of dyadic
L:
applications:
a
┌───┬──────────────────┐
│1 2│┌────┬───────────┐│
│ ││abcd│0 1 2 3 4 5││
│ │└────┴───────────┘│
└───┴──────────────────┘
c
┌─────┬─────┐
│┌───┐│┌───┐│
││ABC│││DEF││
│└───┘│└───┘│
└─────┴─────┘
a ;L:0 c
┌───────────┬──────────────────────────────┐
│┌─────────┐│┌──────────┬─────────────────┐│
││┌───┬───┐│││┌────┬───┐│┌───────────┬───┐││
│││1 2│ABC│││││abcd│DEF│││0 1 2 3 4 5│DEF│││
││└───┴───┘│││└────┴───┘│└───────────┴───┘││
│└─────────┘│└──────────┴─────────────────┘│
└───────────┴──────────────────────────────┘
a ;L:1 c
┌─────────┬────────────────────────┐
│┌───┬───┐│┌──────────────────┬───┐│
││1 2│ABC│││┌────┬───────────┐│DEF││
│└───┴───┘│││abcd│0 1 2 3 4 5││ ││
│ ││└────┴───────────┘│ ││
│ │└──────────────────┴───┘│
└─────────┴────────────────────────┘
Maybe I'll do less extra boxing for enabling each
as in
(;:'foo bar') ,each <'extraboxhere'
┌───────────────┬───────────────┐
│fooextraboxhere│barextraboxhere│
└───────────────┴───────────────┘
and employ L: instead in the future:
(;:'foo bar') ,L:0 'noextraboxhere'
┌─────────────────┬─────────────────┐
│foonoextraboxhere│barnoextraboxhere│
└─────────────────┴─────────────────┘
We'll see.