Menu

Home

Bruce Martin

Welcome to your wiki!

This is the default page, edit it as you see fit. To add a new page simply reference it within brackets, e.g.: [SamplePage].

The wiki uses Markdown syntax.

Project Members:


Discussion

  • Kara

    Kara - 2020-09-11

    Hi Bruce, Glad you come up with Cobol2Json Converter. It is going to be very helpful. I am trying to see the examples on github and also tried to change Cobol to Json. But there was no luck. Most of the examples uses "dot bin " files and I don't know what is the use of that file. Is there a simple example that takes "dot cbl" file and change it to "dot json" file? I really appreciate that.
    Here is my sample code.

    try{
        Cobol2Json.newCobol2Json("sample.cbl")
            .setFont("cp037")
            .setFileOrganztion("Constants.IO_FIXED_LENGTH")
            .setSplitcopybook(CopybookLoader.SPLIT_NONE)
            .setTagFormat(IReformatFieldName.RO_UNDERSCORE)
            .cobol2json (new FileInputStream("sample.cbl"), new FileOutputStream("sample.json"))
    } catch (Exception e){
        System.out.println("....Exception..."+e.getMessage());
    }
    

    It is giving me this output:
    ....Exception...null.
    Is there anythign I missed?

     

    Last edit: Bruce Martin 2020-09-12
  • Bruce Martin

    Bruce Martin - 2020-09-12

    I need the full stack trace but obvious errors are

    • You have use the same file for both the cobol copybook and the data file.

    I would expect

        Cobol2Json.newCobol2Json("sample.cbl")
            .setFont("cp037")
            .setFileOrganztion("Constants.IO_FIXED_LENGTH")
            .setSplitcopybook(CopybookLoader.SPLIT_NONE)
            .setTagFormat(IReformatFieldName.RO_UNDERSCORE)
            .cobol2json (new FileInputStream("sample_data_file.txt"), new FileOutputStream("sample.json"))
    

    the Cobol Copybook (sample.cbl) describes the file and will look like:

            01 Record-Name.
                     03 Field-1                         pic x(10).
                     03 Field-7                         pic s9(09)v99.
                     ....
    

    The Data File (sample_data_file.txt) will have the raw data in the format described by the Copybook.


    Finally the

    • RecordEdito (https://sourceforge.net/projects/record-editor/)
    • ReCsvEditor (https://sourceforge.net/projects/recsveditor/

    Both have code generators for cblToJson. I will put together a Wiki for this in the next day or so.

     
  • Bruce Martin

    Bruce Martin - 2020-09-12

    I have created a Wiki on the RecordEditor/ReCsvEditor generate option

     
  • Kara

    Kara - 2020-09-14

    Thanks Bruce, I was to mean to put the data file and the schema and convert to json.
    Now I want to do exactly the reverse, change the JSON to Cobol format. I don't see any method in the Cobol2Json class. Does it do that? If so sample code that can convert Json back to Cobol?

     
  • Kara

    Kara - 2020-09-14

    From the Screenshot you shared on wiki, it looks like the Cbl2Json converter is only one way? I see the Cbl2Xml and Cbl2Csv are two ways. Is that the case that I can't change Json back to Cobol with the new Cbl2Json Library? So what is better solution?

     
  • Bruce Martin

    Bruce Martin - 2020-09-15

    Yes Cbl2Json is one way converter (The others are 2 ways). I will have a look at what is involved in doing 2 wayin the next couple of days/ (from memory it was going to be harder than Xml). Not a lot of people use the Convert though.

     
  • Kara

    Kara - 2020-09-15

    Okay, I will try to use the cbl2xml by converting the json to xml and then to cbl. I have 0.90.2 (Cb2Xml and Jrecord)jar and I don't see the class Cobol2Xml, is there anything I missed?
    I want to use use the
    Cobol2Xml.newCobol2Xml ("sample.cbl")
    .
    .
    .
    .etc
    .xml2Cobol("sample.xml", "sample.txt");

     
  • Moddy Te'eni

    Moddy Te'eni - 2020-10-15

    Hi Bruce,
    Thanks you for maintaining this project.

    I'm trying to write code that converts a copybook to a sample JSON based on your code (speciifcally, Cobol2JsonImpl.java). I managed to do it but I got NullPointerException from cb2xml, couldn't debug since I didn't find sources for the libs you used. Thereore I use newer versions (cb2xml-1.01.1 and JRecord-0.90.2) However, these new versions are significantly different, so I had to change your code. I changed

    List<? extends IItem> items = cobolSchemaDetails.cobolCopybook.getCobolItems();
    

    to

    List<Item> items = cobolSchemaDetails.recordItems.stream().flatMap( ri -> ri.items.stream()).collect(toList());

    And it works now for the files I tested, but I'm not sure it is the right thing to do. So my questions are:
    1. Where can I get the sources for the libraries you used?
    2. Conversly (and a better option for me), do you have a newer version of CobolToJson that uses newer versions of cb2xml-1.01.1 and JRecord-0.90.2?
    3. Would like me to share with you my code of copybook-to-json-sample as a contribution?

    Cheers

     
  • Bruce Martin

    Bruce Martin - 2020-10-16

    The versions in Git-Hub should be fairly recent, I will yty to update them shortly

     
  • Moddy Te'eni

    Moddy Te'eni - 2020-10-19

    Do you mean you'd make CobolToJson work with the latest JRecord? That would be great!

     
  • Bhuvana

    Bhuvana - 2020-10-28

    Thanks for maintaining this project. It would be great if we can make CobolToJson two-way.

     
  • Bruce Martin

    Bruce Martin - 2020-10-28

    I will be releasing a new CobolToJson using the latest JRecord. I am currently updating cb2xml, CobolToCsv and will release them together.

    I will have a look at JSon --> Cobol but it is not a high priority

     
  • samuel dion

    samuel dion - 2022-09-21

    Hi Bruce, any updates on the JSON schema --> cobol ?. Thank you

     
  • Bruce Martin

    Bruce Martin - 2022-09-22

    There is no JSON Schema --> Cobol Copybook

    The latest version should do JSON_Data --> Cobol_Data (with a lot of limitations) e.g.

            Cobol2JsonSchema.newCobol2Json(Cbl2JsonCode.getFullName("cobol/amsPoDownload.cbl"))
              .setFileOrganization(IFileStructureConstants.IO_BIN_TEXT)
              .setSplitCopybook(CopybookLoader.SPLIT_01_LEVEL)
              .setTagFormat(IReformatFieldNames.RO_UNDERSCORE)
    
                 .setRecordSelection("PO-Record", Cobol2Json.newFieldSelection("Record-Type","H1"))
                 .setRecordSelection("Product-Record", Cobol2Json.newFieldSelection("Record-Type","D1"))
                 .setRecordSelection("Location-Record", Cobol2Json.newFieldSelection("Record-Type","S1"))
              .cobol2jsonSchema("G:\\Temp\\aamsPoDownload.def.json");
    

    I have uploaded 0.90.4 version of cobol2json + JRecord should have the latest version of cobol2json

     

Log in to post a comment.