Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Does anyone know of any Rexx JSON support?

312 views
Skip to first unread message

Jeremy Nicoll - news posts

unread,
Sep 10, 2009, 10:44:28 PM9/10/09
to
Does anyone know of Rexx code to read or create JSON files?

(see http://www.json.org )


--
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply
to newsre...@wingsandbeaks.org.uk replacing "nnn" by "284".

bwcherry

unread,
Sep 11, 2009, 12:00:01 PM9/11/09
to
On Sep 10, 10:44 pm, Jeremy Nicoll - news posts

<jn.nntp.scrap...@wingsandbeaks.org.uk> wrote:
> Does anyone know of Rexx code to read or create JSON files?
>
> (seehttp://www.json.org)
>
> --
> Jeremy C B Nicoll - my opinions are my own.
>
> Email sent to my from-address will be deleted. Instead, please reply
> to newsreply...@wingsandbeaks.org.uk replacing "nnn" by "284".  

This might help. It uses arrays and directories (stems are out).
Because I call the makearray method if you do not pass an array or
directory, you could use it for other objects as well (lists, queue,
etc). Created it to work with ooRexx 3.1. The sample below shows how
you might want to serialize a rexx object in JSON. The only other
method you should really care about is the "fromJSON" method. It
requires a string of json text. It returns a rexx object. I think it's
pretty straight forward. Please let me know if you have problems. It
does not handle unicode. I have been using this instead of XML for a
lot of our AJAX websites. Thanks!
--
Brandon Cherry

/* serialize.rex */
test = .array~new()

test~append(.directory~new())
test[test~last]['name'] = 'Adam'
test[test~last]['location'] = 'NC'
test[test~last]['terminated'] = .true
test[test~last]['number'] = 2
test[test~last]['description'] = 'The quick brown fox jumped over the
lazy dog.'.endofline||,
'The quick brown fox jumped over the
lazy dog.'

test~append(.directory~new())
test[test~last]['name'] = 'Bob'
test[test~last]['location'] = 'SC'
test[test~last]['terminated'] = .false
test[test~last]['number'] = 10
test[test~last]['description'] = .nil

test~append(.directory~new())
test[test~last]['name'] = 'Carl'
test[test~last]['location'] = 'VA'
test[test~last]['terminated'] = .false
test[test~last]['number'] = 15
test[test~last]['description'] = .nil

say .json~new()~toJSON(test)

::requires 'json.cls'

json.cls
<http://learning.safedataisp.net/ajax/json.cls>

Jeremy Nicoll - news posts

unread,
Sep 19, 2009, 3:19:21 PM9/19/09
to
bwcherry <brandon...@gmail.com> wrote:

> This might help...

Thank-you. I've done a little experimenting and it looks useful so far. My
only real problem is not well understanding the oo aspects of the code too
well. I may be back with questions in due course.

I found a useful utility on the net which 'pretty-prints' a JSON structure,
eg reading it from a file. The output can be redirected into a second file,
making it a quick and easy way to get a look at a structure's contents.

The pretty-printing, if one does it in a Windows console / command window,
is displayed with colouring of the contents, somewhat like a text editor's
syntax colouring, which looks very nice! The utility (and a picture of
coloured output) is at:

http://www.raboof.com/Projects/TidyJson/


--
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply

to newsre...@wingsandbeaks.org.uk replacing "nnn" by "284".

0 new messages