Re: Convenient Representations of XML/JSON
Posted: Sat Nov 22, 2014 12:40 am
A good summary. No disagreement but I came away with a different emphasis.
I think we all came away agreeing that the tabular form of ⎕XML was not necessarily the easiest thing to work with and that something a bit closer to - if not an exact copy of - APL data would be more appropriate.
JSON to APL.
Agreed JSON object keys ("strings") don't necessarily map to APL names so in general converting JSON objects to APL spaces is out. We need one or other of the array formats enumerated above.
APL to JSON.
Wouldn't it be nice if we could serialize absolutely anything. Without some pre-agreed protocol - Stephen suggested a distinguished first element (perhaps "Dyalog 8.0") - we can't serialize:
So, a contradiction. Stephen pointed out that a "round trip" doesn't necessarily imply a pair of mutual inverses. We can start with a space:
It was unclear to me whether Morten's original question implied an eventual one-size-fits-all solution or perhaps an option or two. Given that objects originating from sources other than APL are quite unlikely to have string keys being valid APL names perhaps the default should be an associative array as (iii) with an option to render objects as spaces (i) to be used if we are sure of the source.
Chris pointed out that as most of the contention surrounds the representation of dictionaries then perhaps an APL enhanced protocol for JSON should be called JOHNSON. We were, after all, meeting within three or four furlongs of the great man's house.
I think we all came away agreeing that the tabular form of ⎕XML was not necessarily the easiest thing to work with and that something a bit closer to - if not an exact copy of - APL data would be more appropriate.
JSON to APL.
Agreed JSON object keys ("strings") don't necessarily map to APL names so in general converting JSON objects to APL spaces is out. We need one or other of the array formats enumerated above.
APL to JSON.
Wouldn't it be nice if we could serialize absolutely anything. Without some pre-agreed protocol - Stephen suggested a distinguished first element (perhaps "Dyalog 8.0") - we can't serialize:
- empty arrays other than '' (and ⍬ if we can agree that that is what JSON null should represent)
multidimensional arrays
scalars or 1-item vectors (take your pick - we can have one or other but not both)
So, a contradiction. Stephen pointed out that a "round trip" doesn't necessarily imply a pair of mutual inverses. We can start with a space:
s←{⍵⊣⍵.(a b c)←0 1 2}⎕ns'' ⍝ (i)produce intermediate JSON
'{a: 0, b: 1, c: 2}' ⍝ (ii)and end up back in APL with array
s←((,'a')(,'b')(,'c'))(0 1 2) ⍝ (iii)But if we also start with array
a←((,'a')(,'b')(,'c'))(0 1 2) ⍝ (iv)two things that started out different are now the same.
It was unclear to me whether Morten's original question implied an eventual one-size-fits-all solution or perhaps an option or two. Given that objects originating from sources other than APL are quite unlikely to have string keys being valid APL names perhaps the default should be an associative array as (iii) with an option to render objects as spaces (i) to be used if we are sure of the source.
Chris pointed out that as most of the contention surrounds the representation of dictionaries then perhaps an APL enhanced protocol for JSON should be called JOHNSON. We were, after all, meeting within three or four furlongs of the great man's house.