|
I’m not a fan of online JSON reformatter because you may not exactly know what the site does with that data after you are done. I’ve read articles (long forgotten links) about some sites being rather sketchy in the hopes example data uploaded by individuals might have data to extract.
There are free parsers that you use on your workstation to do exactly this. I used TextWrangler (now BBEdit). You can download a script for the editor which when applied to the code, will reformat it in an easily-readable format. Nothing ever leaves your workstation, and for certain, you’re not giving any secrets out to unknown websites.
Here’s a link of how it’s done.
https://blog.scottlowe.org/2013/11/11/making-json-output-more-readable-with-bbedit/ <https://blog.scottlowe.org/2013/11/11/making-json-output-more-readable-with-bbedit/>
Just my 2-cents.
Eddie
On Jan 20, 2020, at 10:49 AM, DAVID LERMAN <davidlerman@xxxxxxxxxxx> wrote:
Everything I know about parsing and creating JSON documents I learned from Scott Klement. Thank you Scott.
http://scottklement.com/yajl/
I also learned that it is really nice to have valid, easy to read JSON documents so I found https://codebeautify.org
Here you can validate, and "beautify" your document. For me this helped create the structure to place the values in.
If you would like I would be happy to put some code snippets in this thread for things you may have to do. Examples are find all the nodes you know you will need before you start your parse or send back and error about what you could not find.
Here is how I did dates.
when key = 'StartDate';
TimeStampISO50 = %trim(yajl_get_string(val));
TimeStampISO50 = %xlate( 'T:' : '-.' : TimeStampISO50 );
TimeStampISO50 = %subst(TimeStampISO50:1:10) + '-' +
%subst(TimeStampISO50:12:8) + '.000000';
result.list(i).StartDt = %timestamp(%trim(TimeStampISO50));
I have more if you want them just ask. below is your JSON beautified.
[
{
"Count": "2",
"DataSrc": "qs0wseoc03:8882,qs5b:21",
"Oper": "GetQuoteSnap",
"Time": "2020-01-16T21:55Z 132ms",
"UserID": "ws@xxxxxxxx"
},
{
"Attr": {
"DTE": "15",
"Market": "1271",
"MarketName": "nymex",
"RequestedSymbol": "QHO@1",
"Status": "0",
"TickerSymbol": "QHOG20",
"Vendor": "DTN"
},
"Data": {
"TradeDateTime": "2020-01-16T16:44:11.766-05:00",
"BidDateTime": "2020-01-16T16:45:02.038-05:00",
"AskDateTime": "2020-01-16T16:45:02.040-05:00",
"SettleDateTime": "2020-01-16T14:32:05.413-05:00",
"BateDateTime": "2020-01-16T16:45:02-05:00",
"LastBidAsk": "1.8661",
"LbaChange": "-0.0118",
"Latest": "1.8661",
"Recent": "1.8656",
"ContractDate": "2020-02-01",
"Previous": "1.8779",
"Open": "1.883",
"Open2": "",
"High": "1.8891",
"Low": "1.8567",
"Close": "",
"Close2": "",
"SettlementPrice": "1.86",
"Volume": "89633",
"LastVolume": "1",
"CumVolume": "82953",
"OpenInterest": "83051",
"Bid": "1.8657",
"Bid1": "",
"Bid2": "",
"Ask": "1.8661",
"Ask1": "",
"Ask2": "",
"First": "1.883",
"Last": "1.8656",
"BidSize": "2",
"AskSize": "2",
"TradeCount": "27238",
"TradeCondition": "0",
"MarketCondition": "0",
"BateCodeLast": "1",
"BateCodeOpen": "0",
"BateCodeHigh": "0",
"BateCodeLow": "0",
"BateCodeClose": "0",
"BateCodeOpen2": "0",
"BateCodeClose2": "0",
"Direction": "0",
"Fraction": "4",
"FractionVen": "21",
"FractionDsp": "4",
"Settledate": "2020-01-16",
"ExpirationDate": "2020-01-31",
"DaysToExpiration": "15",
"SeqNum": "5395680",
"PermCode1": "1426070793",
"PermCode2": "0",
"CntrHigh": "2.3875",
"CntrLow": "1.6475",
"ContractHighDate": "2018-10-02",
"ContractLowDate": "2017-04-27",
"TickSize": "0.0001",
"SymType": "Commodity.Future.Single.None",
"Change": "-0.0123",
"Market": "1271",
"Zone": "30",
"Week52High": "",
"Week52Low": "",
"Wk52HighDate": "",
"Week52LowDate": "",
"XchgId": "29",
"SrcIdn": "5",
"ExercisePrice": "0",
"IssueDescription": "NEW YORK HARBOR ULSD February 2020",
"Month": "Feb 20",
"VenSymbol": "HOG20",
"CallRoot": "QHO",
"PutRoot": "QHO",
"NumOptMths": "36",
"OptPrcMult": "1.0",
"UserDescription": "NEW YORK HARBOR ULSD",
"FirstActivity": "2016-11-30",
"DeliveryDate": "2020-02-27",
"FirstDeliveryDate": "",
"Volatility": "0.2669000029563904",
"OpenRange1": "",
"OpenRange1Bate": "",
"OpenRange2Bate": "",
"CloseRange1": "",
"CloseRange1Bate": "",
"CloseRange2Bate": "",
"Ltrade": "1.8656",
"SettlementChange": "-0.0179",
"VolumeDayCode": "16",
"FIGI": "BBG00FD8C1N3",
"Vendor": "TK02",
"QuoteDelay": "10",
"TotalContractCumulativeVolume": "337574",
"TotalContractOpenInterest": "427779",
"TotalContractOpenInterest2": "0",
"TotalContractVolume": "332162",
"TotalContractVolume2": "0",
"DTNTotalContractCumulativeVolume": "337574",
"DTNTotalContractVolume": "332162",
"DTNTotalContractOpenInterest": "427779",
"DTNTotalContractVolume2": "0",
"DTNTotalContractOpenInterest2": "0",
"OneDigitYearSymbol": "QHO@1",
"ActualSymbol": "QHOG20"
}
},
{
"Attr": {
"DTE": "15",
"Market": "1271",
"MarketName": "nymex",
"RequestedSymbol": "QRB@1",
"Status": "0",
"TickerSymbol": "QRBG20",
"Vendor": "DTN"
},
"Data": {
"TradeDateTime": "2020-01-16T16:45:02.234-05:00",
"BidDateTime": "2020-01-16T16:45:02.234-05:00",
"AskDateTime": "2020-01-16T16:45:02.206-05:00",
"SettleDateTime": "2020-01-16T14:31:10.877-05:00",
"BateDateTime": "2020-01-16T16:45:02-05:00",
"LastBidAsk": "1.6599",
"LbaChange": "0.0231",
"Latest": "1.6599",
"Recent": "1.66",
"ContractDate": "2020-02-01",
"Previous": "1.6368",
"Open": "1.6499",
"Open2": "",
"High": "1.6613",
"Low": "1.6344",
"Close": "",
"Close2": "",
"SettlementPrice": "1.6548",
"Volume": "72693",
"LastVolume": "1",
"CumVolume": "49854",
"OpenInterest": "87878",
"Bid": "1.6599",
"Bid1": "",
"Bid2": "",
"Ask": "1.6603",
"Ask1": "",
"Ask2": "",
"First": "1.6499",
"Last": "1.66",
"BidSize": "1",
"AskSize": "3",
"TradeCount": "18500",
"TradeCondition": "0",
"MarketCondition": "0",
"BateCodeLast": "2",
"BateCodeOpen": "0",
"BateCodeHigh": "0",
"BateCodeLow": "0",
"BateCodeClose": "0",
"BateCodeOpen2": "0",
"BateCodeClose2": "0",
"Direction": "0",
"Fraction": "4",
"FractionVen": "21",
"FractionDsp": "4",
"Settledate": "2020-01-16",
"ExpirationDate": "2020-01-31",
"DaysToExpiration": "15",
"SeqNum": "6068202",
"PermCode1": "1426070793",
"PermCode2": "0",
"CntrHigh": "1.8011",
"CntrLow": "1.326",
"ContractHighDate": "2020-01-07",
"ContractLowDate": "2018-12-31",
"TickSize": "0.0001",
"SymType": "Commodity.Future.Single.None",
"Change": "0.0232",
"Market": "1271",
"Zone": "30",
"Week52High": "",
"Week52Low": "",
"Wk52HighDate": "",
"Week52LowDate": "",
"XchgId": "29",
"SrcIdn": "5",
"ExercisePrice": "0",
"IssueDescription": "RBOB GASOLINE February 2020",
"Month": "Feb 20",
"VenSymbol": "RBG20",
"CallRoot": "QRB",
"PutRoot": "QRB",
"NumOptMths": "0",
"OptPrcMult": "1.0",
"UserDescription": "RBOB GASOLINE",
"FirstActivity": "2016-11-30",
"DeliveryDate": "2020-02-28",
"FirstDeliveryDate": "",
"Volatility": "0.3086000084877014",
"OpenRange1": "",
"OpenRange1Bate": "",
"OpenRange2Bate": "",
"CloseRange1": "",
"CloseRange1Bate": "",
"CloseRange2Bate": "",
"Ltrade": "1.66",
"SettlementChange": "0.018",
"FIGI": "BBG00FSF5621",
"VolumeDayCode": "16",
"Vendor": "TK02",
"QuoteDelay": "10",
"TotalContractCumulativeVolume": "160125",
"TotalContractOpenInterest": "422935",
"TotalContractOpenInterest2": "0",
"TotalContractVolume": "220621",
"TotalContractVolume2": "0",
"DTNTotalContractCumulativeVolume": "160125",
"DTNTotalContractVolume": "220621",
"DTNTotalContractOpenInterest": "422935",
"DTNTotalContractVolume2": "0",
"DTNTotalContractOpenInterest2": "0",
"OneDigitYearSymbol": "QRB@1",
"ActualSymbol": "QRBG20"
}
}
]
Sincerely,
David H. Lerman
44 Paradise Road
Bridgeton, NJ 08302-5501
DavidLerman@xxxxxxxxxxx
On January 20, 2020 at 11:57 AM Jason Olson <josys36@xxxxxxxxx> wrote:--
Thank you!
We'll just use the subprocedures then.
Thanks,
Jason E. Olson
IBM i Engineer/Developer
josys36@xxxxxxxxx
480.223.2952
On Mon, Jan 20, 2020 at 10:52 AM Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx>
wrote:
Hi Jason,--
You won't be able to use this with DATA-INTO because it uses abilities
not available in RPG. Specifically, it creates an array where different
elements are of different types, which isn't possible in RPG. This
rules out DATA-INTO and YAJLGEN.,
You can handle it with YAJL by calling the YAJL subprocedures, though.
-SK
On 1/20/2020 8:53 AM, Jason Olson wrote:
So a colleague of mine has been trying to parse the attached JSON file.hasn't
We've tried 18 different ways to Sunday to get it to parse but the YAJL
utility does not like it.
I tried the new data structure generator in YAJL but it only generated a
small portion of the DS necessary. And, trying to write them by hand
been working either.eyes
So, I figured since we've looked at this maybe someone with more fresh
and has done much more of this would be able to help.--
Thanks,
Jason E. Olson
IBM i Engineer/Developer
josys36@xxxxxxxxx
480.223.2952
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.
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.