Dealing with JSON streams

5 views
Skip to first unread message

Bill Farrell

unread,
Mar 26, 2015, 12:30:45 PM3/26/15
to InterSy...@googlegroups.com
Hi all,

Just today I managed to get the company I'm contracting with to upgrade their Cache instance from 2009 to 2015. This is ahead of a project that will entail receiving a rather huge JSON blob from a mobile device. I think I kindasorta see what I need in Lee's tip here https://sites.google.com/site/intersystemsmv/home/a-cache-of-tips/usingjsonoutsideofzen but I want to wrap my head around the input and output before I start barging into legacy code.

Currently, the app accepts a string (since that's what %request gives me) and deals with a fairly small object containing two, three, maybe five or six array elements (call it tickets). Since before 2015 (likely a lot earlier) some pieces of the request might be a stream. That's easy to tell whether you've got a stream or string with $ISOBJECT(). With phones, the element with the JSON in it was small enough to be a string (until we hit a size limit without streams which we coded around until we could upgrade). With the new black-boxes the status update message Cache will receive could contain hundreds of these ticket elements.

The decryption part is easy since Cache now can decrypt a stream and hand you back a nice stream. Now I still have a stream of plain-text JSON I need to turn into an %ArrayOfDataTypes. Rather than passing in and getting out a Person object (per the example), can I have a plain %ArrayOfDataTypes? If that's the case then my coding job is already near complete; I can use existing logic since it doesn't care how small or huge the array is.

I'm looking at a ton of legacy DSM-looking code, several new spec documents, and a load of nice, shiny, new features in 2015 (LOVE the Studio!). Any hint or boost to cut my study time down would be appreciated. As most projects go, this one is typical: "We need it done a month ago so we're giving you the spec today" <lol>

Here's hoping,
Bill

Bill Farrell

unread,
Jul 31, 2015, 12:46:44 PM7/31/15
to InterSystems: MV Community, james.west...@gmail.com
I wound up writing my own that recurses automatically and creates the expected type of subobject. It's part of a rapid-development framework I'm just now starting to publish as a "working beta with some TODOs". I'll attach the code here. Any MV or COS programmer can get it working in their own system in a few minutes needed to disconnect a couple of spots from the framework. This has been tested to satisfaction in Cache 2015 but I'll gladly take bug reports and improvements.

Bill
CJSON.xml

Joshua Barney

unread,
Jul 31, 2015, 1:17:35 PM7/31/15
to InterSystems: MV Community, james.west...@gmail.com
I used the JSON parser that is available on github, works beautifully


On Thursday, March 26, 2015 at 12:30:45 PM UTC-4, Bill Farrell wrote:

Joshua Barney

unread,
Jul 31, 2015, 1:30:59 PM7/31/15
to InterSystems: MV Community, james.west...@gmail.com
Sorry here is the link: https://github.com/PlanetCache/CacheJSON/blob/master/CacheJSON.cls

I look for %request.ContentType to be application/json
set content = %request.Content.Read()
Set JSON = ##class(WebService.CacheJSON).Decode(CONTENT)
then to access the data
Set name = JSON.GetAt("name")

I have it setup so that if the ContentType is not application/json they receiver page expects the information to come in as parameters so that one page can handle either style


On Thursday, March 26, 2015 at 12:30:45 PM UTC-4, Bill Farrell wrote:

Rich Taylor

unread,
Aug 3, 2015, 10:06:47 PM8/3/15
to InterSy...@googlegroups.com, james.west...@gmail.com

Joshua and Bill,

 

Recent versions of Caché say 2014.1 and above, have very robust support for JSON.  Once you can get up to those releases I would suggest that you check this out.

 

Richard S Taylor
Sales Engineer
InterSystems Corporation
Office: 443-340-8614
FAX: 440-815-5805

Advanced Software technologies for Breakthrough applications 

--
You received this message because you are subscribed to the Google Groups "InterSystems: MV Community" group.
---
You received this message because you are subscribed to the Google Groups "InterSystems: MV Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to InterSystems-...@googlegroups.com.
To post to this group, send email to InterSy...@googlegroups.com.
Visit this group at http://groups.google.com/group/InterSystems-MV.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages