× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Jason,

On 1/20/2020 10:57 AM, Jason Olson wrote:
We'll just use the subprocedures then.


I was looking over your document again since I had some time this morning.  It looks like the basic structure is that the first array element is information about the other array elements... like header-level info about the document you're parsing.

As such, I was thinking a good approach might be to do the following (see sample code below).  I am not sure about the proper sizes, etc, for all of the fields, and I didn't take the time to code all of them, but I think this will give you the idea of what I'd do.

Hope it helps!

**free
ctl-opt dftactgrp(*no) bnddir('YAJL');

/copy yajl_h

dcl-ds Info qualified;
  Count   int(10);
  DataSrc varchar(100);
  Oper    varchar(50);
  Time    varchar(30);
  UserId  varchar(100);
end-ds;

dcl-ds Item qualified dim(50);
  dcl-ds Attr;
    DTE             char(2);
    Market          char(4);
    MarketName      varchar(100);
    RequestedSymbol varchar(10);
    Status          char(1);
    TickerSymbol    varchar(10);
    Vendor          char(3);
  end-ds;
  dcl-ds Data;
    TradeDateTime   varchar(30);
    // ...  etc ...
  end-ds;
end-ds;

dcl-s docNode like(yajl_val);
dcl-s infoObj like(yajl_val);
dcl-s itemObj like(yajl_val);
dcl-s attrObj like(yajl_val);
dcl-s dataObj like(yajl_val);
dcl-s errMsg  varchar(500);
dcl-s ItemNo  int(10);

docNode = yajl_stmf_load_tree('jasonOlson.json': ErrMsg);
if docNode = *null or errMsg <> '';
  // display errMsg, or whatever you wish to do when there's an error
  *inlr = *on;
  return;
endif;


// The first element of the array is an object
// containing header-level information about the
// document.

infoObj = YAJL_ARRAY_ELEM(docNode: 1);

Info.Count   = %int(getObjString(infoObj: 'Count'));
Info.DataSrc = getObjString(infoObj: 'DataSrc');
Info.Oper    = getObjString(infoObj: 'Oper');
Info.Time    = getObjString(infoObj: 'Time');
Info.UserId  = getObjString(infoObj: 'UserID');


// Array elements 2+ are the actual data items that
// the header info refers to.

for ItemNo = 1 to Info.Count;
   itemObj = YAJL_ARRAY_ELEM(docNode: ItemNo+1);

   AttrObj = yajl_object_find(itemObj: 'Attr');
   Item(ItemNo).Attr.DTE             = getObjString(AttrObj: 'DTE');
   Item(ItemNo).Attr.Market          = getObjString(AttrObj: 'Market');
   Item(ItemNo).Attr.MarketName      = getObjString(AttrObj: 'MarketName');
   Item(ItemNo).Attr.RequestedSymbol = getObjString(AttrObj: 'RequestedSymbol');
   Item(ItemNo).Attr.Status          = getObjString(AttrObj: 'Status');
   Item(ItemNo).Attr.TickerSymbol    = getObjString(AttrObj: 'TickerSymbol');
   Item(ItemNo).Attr.Vendor          = getObjString(AttrObj: 'Vendor');

   DataObj = yajl_object_find(itemObj: 'Data');
   Item(ItemNo).Data.TradeDateTime   = getObjString(DataObj: 'TradeDateTime');
   // .. etc ...
endfor;

yajl_tree_free(docNode);

*inlr = *on;
return;


// --------------------------------------------------------------------
//   getObjString():  "Shortcut" subprocedure to get a field in an
//                    YAJL object and interpret it as a string.
//                    if the field is not found, this returns an
//                    empty string.
// --------------------------------------------------------------------

dcl-proc getObjString;

  dcl-pi *n varchar(1000);
    obj like(yajl_val) value;
    key varchar(100) const;
  end-pi;

  dcl-s node like(yajl_val);
  dcl-s retval varchar(1000);

  node = yajl_object_find(obj: key);
  if node = *null;
    retval = '';
  else;
    retval = yajl_get_string(node);
  endif;

  return retval;
end-proc;


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.