Jump to content
IGNORED

COMING SOON: JSON Parsing for N:


Recommended Posts

Hello everyone,

A year ago, I had to rewrite the network code. It meant that the JSON parser that I had originally written, was taken out, until I could replace it.

I have now done the first pass of the JSON parser, which allows one to:

 

  • Open a connection to some JSON data, e.g. (N:HTTPS://oldbytes.space/api/v1/timelines/public?limit=1)
  • Set the channel mode to JSON (XIO 252,#1,12,1,"N:")
  • Tell the JSON parser to parse that information (XIO ASC("P),#1,12,0,"N:")

 

And from this point, the JSON document is parsed in the FujiNet, and can be queried for any pieces of information you wish to retrieve, e.g.

XIO ASC("Q"),#1,12,0,"N:/0/account/display_name"

And it will be returned via the I/O channel, ready to be picked up with a CIO GET CHARACTER or GET RECORD call e.g.

INPUT #1,NAME$

 

The current JSON parser will parse all of the JSON primitives.

 

An example of this, is the world's simplest Mastodon client, written in ATARI BASIC, which displays the newest public post:

 

0 DIM A$(256)
10 OPEN #1,12,0,"N:HTTPS://oldbytes.space/api/v1/timelines/public?limit=1"
11 TRAP 91
20 XIO 252,#1,12,1,"N:":REM  SET CHANNEL MODE
30 XIO ASC("P"),#1,12,0,"N:":REM PARSE JSON
40 XIO ASC("Q"),#1,12,0,"N:/0/created_at"
50 INPUT #1,A$:? A$
60 XIO ASC("Q"),#1,12,0,"N:/0/account/display_name"
70 INPUT #!,A$:? A$
80 XIO ASC("Q"),#1,12,0,"N:/0/content/"
90 GET #1,A:? CHR$(A);:GOTO 90
91 CLOSE #1:END

 

Yes, really, that's it.

 

And you get something like this:

 

20220515_110504.thumb.jpg.8ae38155aca286a27ee4a255edf624a5.jpg

 

It will be in the next released build for both Atari and Coleco Adam, which will be released very soon.

 

-Thom

  • Like 4
Link to comment
Share on other sites

  • 2 months later...

It seems that the data extraction is not random access, and the order of keys gets reversed. So given:
{

"A":

   {"one":

        {"a":"hello"},

        {"b":"world"}

    },

    {"two":

         {"a":"foo"},

         {"b":"bar"}

    },

"B":

    {

         {"the":"end"}

    }

}   

 

Parses to a stream like:

/B/the:end

/A/two/b:bar

/A/two/a:foo

/A/one/b:world

/A/one/a:hello

 

if I Query "/A/one/a" the read cursor advances to the end of the stream and the preceding parts, that appear later in the original JSON, become inaccessible.

At least that's what the pulled out hair that got stuck in my keyboard seems to indicate, just kidding, I'm too olde to have any hair left.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...