0

We have a problem while viewing the JSON file that contains "\r\n" fetched from DB2 (encoding scheme EBCDIC). When we check the content of the attribute with TOAD directly in the database, we see that we have correct Hex-values for CRLF.

0D and 0A are hex values for CRL

We are fetching this data from DB2 as json format . While viewing the json file it gets converted to the below format

C2 and 85 gets formed . Could notice a spurious charcter Â...

And NotedPadd++(UTF-8) while viewing the JSON "NEL" is being displayed . When i convert the file to ANSI i could notice Â...

I am writing to file as in below code (sample code.)

            output = new FileOutputStream(tempFile);
            IOUtils.write(getBytes(), output);

    public byte[] getBytes() {
    String data = "{\r\n" "dataLists" : [ ]}";
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    byteArrayOutputStream.write(data.getBytes("UTF-8"));
    return byteArrayOutputStream.toByteArray();
   }

Please help.

Chammu
  • 103
  • 3
  • 13
  • 1
    Ebcdic only has one end-of-line character not 2. Sending a \r\n is not a good idea.Try ` String data = "{\n" "dataLists" : [ ]}";` – Bruce Martin Feb 19 '20 at 22:11
  • @BruceMartin : Okay. But one small clarification while viewing the data from database i am able to view the "\r\n" - hex values (1A, 20). Only on viewing the data it gets modified to "C2, 85" . Does it imply fetching data through getBytes() modified the CRLF "\r\n" ? – Chammu Feb 20 '20 at 11:04
  • `getBytes()` should not modify the data. C2, 85 is Be in ebcdic, I do not know wharethat is comng from – Bruce Martin Feb 20 '20 at 22:17

1 Answers1

0

JSON is based on JavaScript, and as part of the JavaScript definition it says that NEL characters could be translated into white spaces.

Based on that, if you don't want to have problems while viewing data imported from mainframe, you can convert the NEL characters into a white space.

enter image description here

Also, in this definition we can see that it can be converted into a white space

AngocA
  • 7,655
  • 6
  • 39
  • 55