tschak909 Posted May 15, 2022 Share Posted May 15, 2022 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: It will be in the next released build for both Atari and Coleco Adam, which will be released very soon. -Thom 4 Quote Link to comment Share on other sites More sharing options...
apc Posted May 18, 2022 Share Posted May 18, 2022 (edited) I will try to add JSON parser into FujiNet-PC Edited May 18, 2022 by apc 5 Quote Link to comment Share on other sites More sharing options...
Nick Stefanisko Posted July 25, 2022 Share Posted July 25, 2022 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. Quote Link to comment Share on other sites More sharing options...
tschak909 Posted July 25, 2022 Author Share Posted July 25, 2022 Thank you for hacking on this! If there's something goofy going on, it's most likely in this object: https://github.com/FujiNetWIFI/fujinet-platformio/blob/master/lib/fnjson/fnjson.cpp The JSON commands set pointers in here, maybe some bad assumptions are being made? -Thom Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.