|
Base64 always preserves the binary value of the data. That's what it's
all about. So if you want the data to be decoded in (which is weird for
an application newer that 1998 -- ASCII has mostly been replaced with
unicode.)
Your steps will look like this:
1) Get the ASCII data (in ASCII format) and encode it in base64.
2) Put the encoded data in your JSON field. If the JSON building tool
you're using is expecting input in EBCDIC, make sure you've converted
the base64-encoded string to EBCDIC (it won't change the underlying
values once decoded.)
3) Create your JSON document (which should be encoded in UTF-8 --a
version of Unicode -- that's the standard for JSON -- which means your
encoded string will also be encoded in UTF-8... again, it won't change
the underlying value.)
4) Encode the JSON document in base64 as well.
5) Send the result whereever it needs to go.
As for IBM-supplied APIs. They provide the Apache Portable Runtime
(APR) which has base64 routines, I'm not a huge fan, but they exist.
SQL also has a base64 function, that works nicely, aside from the fact
that it has a relatively short string length, which can be an issue
sometimes.
For creating JSON, I would either use SQL or DATA-GEN. Personally, I
prefer the latter -- I find it easier and more elegant, other people
prefer SQL... both will do the job.
-SK
On 8/8/2023 6:05 PM, Vinay Gavankar wrote:
Hi,to
I want to create a JSON string where one of the fields needs to be BASE64
encoded. The JSON string will then be converted to ASCII to be sent out
be used by an ASCII based server.different
For example,
{
"Field1" : "aaa",
"Field2" : "bbb",
"Field3" : "ccc"
}
where Value bbb needs to be BASE64 encoded.
I am assuming that BASE64 encoding of EBCDIC and ASCII will give
results, and just encoding bbb in EBCDIC before creating JSON string andcorrect?
then converting full string to ASCII will not do the trick. Is that
Also, what is the best way of BASE64 encoding/decoding using IBM supplied--
APIs?
Any ideas will be greatly appreciated. TIA
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@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.
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.