Skip to main content

Convert cobol copybook to Json and parse data files based on it

Project description

Cobol Copybook JSONifier 🚀

workflow status

📜 CHANGELOG.md

⚡ TL;DR

pip install coboljsonifier
pip install simplejson

# python code begin ---------- 8< ----------------------------------
# bookfname - The Cobol Schema filename
# data      - The Mainframe data filename
import simplejson
from coboljsonifier.copybookextractor import CopybookExtractor
from coboljsonifier.parser import Parser
from coboljsonifier.config.parser_type_enum import ParseType

dict_structure = CopybookExtractor(bookfname).dict_book_structure
parser = Parser(dict_structure, ParseType.BINARY_EBCDIC).build()
parser.parse(data)
dictvalue = parser.value
print(simplejson.dumps(dictvalue))
# python code end ------------ 8< ----------------------------------

# Than run you code:
python3 your_pgm_name

1️⃣ 📖 Introduction

The COBOL Copybook JSONifier is a powerful tool created to streamline the transformation of EBCDIC-encoded data files from mainframes into JSON format through COBOL copybook schemas. This process is essential for the efficient transfer and handling of mainframe data in cloud environments and other contemporary systems. 🌩️

2️⃣ 🤔 Why Choose COBOL Copybook JSONifier?

  • Efficiency: Automates parsing, saving time and effort by eliminating manual conversions.
  • 🔄 Versatility: Compatible with a variety of data types such as binary, COMP3, and numeric fields.
  • 🛠️ Ease of Use: Simple installation and user-friendly setup ensures quick deployment.
  • Reliability: Utilizes COBOL copybooks for precise data conversion, reducing errors.
  • 🤝 Integration: JSON output can be easily incorporated into modern applications for better data manipulation.

This package is particularly useful for organizations transitioning mainframe data to cloud-based solutions, enhancing data accessibility and interoperability. 🚀

3️⃣ 📂 What is this for?

This package is designed to:

  1. Parse mainframe files in EBCDIC format into JSON using COBOL copybook schemas.
  2. Simplify the transfer and processing of mainframe data in modern environments.

What are Mainframe's "Raw Positional Files"?

Raw positional files are structured files where each piece of data is located at a fixed position. Think of them as a library card with designated sections for specific information (e.g., name, due date).

4️⃣ 🛠️ Before Start

  1. Extracting the COBOL Copybook Structure: First, extract the cobol schema from the code and save it to a file like my_schema.cob.

  2. Get the data to process: Save the Mainframe's file to some local place. Something like my_data.bin.

  3. 🚨 Data Transfer Considerations:

    • ☢️ Binary Data: For data types like BINARY, COMP, COMP3, and signed numeric fields ( S9(n)), it is essential to transfer in binary mode to preserve the data's integrity. Transferring these in text mode will corrupt the data during the EBCDIC to ASCII conversion

    • ☢️ Text Data: Only fields defined with PIC 9(n), PIC X(n), and masked numeric fields (PIC +99999.99) can be safely transferred in text mode.

Correct transfer modes prevent data corruption, particularly with binary data types. ⚙️

5️⃣ 🌊 CobolJsonifier Data Flow

COBOL Copybook ➕ Mainframe Data (EBCDIC) ➡️ Parser ➡️ JSON Output ➡️ Cloud Apps, APIs, etc.

CobolJsonifier Data Flow: Parsing Mainframe Data into JSON Outputs

6️⃣ 🚀 Usage

  1. Installing the Package:

    pip install coboljsonifier
    

    📋 Note:

    • To save in json formats is necessary to use simplejson package. It's to keep compatibility of Decimal pakage that is used to handle monetary values.

    • The common json library has incompatibility with Decimal values

    • Install simplejson just running pip install simplejson.

    • Use simplejson the same way of json.

      Ex.
      install simplejson as json
      It will keep compatibility with the main functionalities.

  2. Using the Package:

    import simplejson
    from coboljsonifier.copybookextractor import CopybookExtractor
    from coboljsonifier.parser import Parser
    from coboljsonifier.config.parser_type_enum import ParseType
    
    dict_structure = CopybookExtractor(bookfname).dict_book_structure
    parser = Parser(dict_structure, ParseType.BINARY_EBCDIC).build()
    parser.parse(data)
    dictvalue = parser.value
    print(simplejson.dumps(dictvalue))
    

7️⃣ 📚 Appendix

  • Supported Data Types
=======================================================================================
    TYPES                             CLASSES                          EBCDIC  ASCII   
=======================================================================================
    -[Empty]-------------------------------------------------------------------------- 
    00  Empty Content                 Fieldempty                        yes✅  yes✅   
    -[Numeric Types without signal]--------------------------------------------------- 
    01) 9                             FieldSimpleNumeric                yes✅  yes✅   
    02) 9V99                          FieldSimpleNumericDecimals1       yes✅  yes✅   
    03) 9V9(2)                        FieldSimpleNumericDecimals2       yes✅  yes✅   
    04) 9(12)                         FieldSimpleNumeric1               yes✅  yes✅   
    05) 9(12)V99                      FieldSimpleNumeric1Decimals1      yes✅  yes✅   
    06) 9(12)V9(2)                    FieldSimpleNumeric1Decimals2      yes✅  yes✅   
    -[Numeric Types with signal]------------------------------------------------------ 
    07) S9(12)       [BINARY/COMP3]   FieldSignalNumeric1               yes✅  no ❌   
    08) S9(12)V99    [BINARY/COMP3]   FieldSignalNumeric1Decimals1      yes✅  no ❌   
    09) S9(12)V9(2)  [BINARY/COMP3]   FieldSignalNumeric1Decimals2      yes✅  no ❌   
    -[Masked Numeric Types]----------------------------------------------------------- 
    A1) +99999999999999.99            FieldNumericMasked1               no ❌  yes✅   
        -99999999999999.99                                                             
        +99999999999999                                                                
        +ZZZZZZZZZZZZZ9.99                                                             
        -ZZZZZZZZZZZZZ9.99           (Note: These are just                             
         ZZZZZZZZZZZZZZ.ZZ                         some examples)                      
         99999999999999999                                                             
    -[Alphabetic]--------------------------------------------------------------------- 
    10) A                             FieldSimpleAlphabetic             yes✅   yes✅  
    11) A(12)                         FieldAlphabetic                   yes✅   yes✅  
    -[Alphanumeric]------------------------------------------------------------------- 
    11) X                             FieldSimpleAlphanumeric           yes✅   yes✅  
    13) X(12)                         FieldAlphanumeric                 yes✅   yes✅  
    -[Undefined]---------------------------------------------------------------------- 
    99) None of the above             FieldUndefined                    yes✅   yes✅  
=======================================================================================

🔗 References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coboljsonifier-1.0.8.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

coboljsonifier-1.0.8-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file coboljsonifier-1.0.8.tar.gz.

File metadata

  • Download URL: coboljsonifier-1.0.8.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for coboljsonifier-1.0.8.tar.gz
Algorithm Hash digest
SHA256 ebb715af4fad8d093589fc53433a53f59c6e3356a4b85503d56fb0e699aa7f23
MD5 fc630872eb25cb5ccea91bd415097b4f
BLAKE2b-256 ea639f6d7801eb828c402b454a62f44aee6bfbdaac2c054db3f44e9b0b5e3190

See more details on using hashes here.

File details

Details for the file coboljsonifier-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for coboljsonifier-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 09cd8a9dd29ddb81522e38c6af869b89918428beb1b4908eed1d8aa025113b17
MD5 d5f418a4afad7ca4c4b559adaf3a8d01
BLAKE2b-256 64bdeb7ceee71c97b51a10512aaa94e409c3900c0261afc89596d17813749a79

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page