Skip to main content

Convert COBOL copybooks to JSON schema format

Project description

COBOL Copybook to JSON Schema Converter

A Python utility that converts COBOL copybooks to JSON schema format. This tool is particularly useful for mainframe modernization projects and data integration scenarios where you need to understand and work with COBOL data structures in modern applications.

Features

  • Comprehensive COBOL Support: Handles various COBOL data structures including:

    • Group items and elementary items
    • OCCURS clauses (arrays)
    • REDEFINES clauses
    • Different USAGE types (COMP, COMP-3, etc.)
    • PICTURE clauses with various data types
    • Signed and unsigned numeric fields
  • Dual Usage: Can be used both as a command-line tool and as a Python library

  • Debug Support: Built-in debugging capabilities for troubleshooting

  • Error Handling: Comprehensive error handling with detailed messages

Installation

pip install cobol-copybook-to-json

Usage

Command Line Tool

# Convert a COBOL copybook to JSON schema
cobol-to-json -c input_copybook.cpy -j output_schema.json

# Enable debug mode
cobol-to-json -c input_copybook.cpy -j output_schema.json -d

Python Library

from cobol_copybook_to_json import convert_copybook_to_json

# Read your COBOL copybook
with open('your_copybook.cpy', 'r') as f:
    copybook_content = f.read()

# Convert to JSON schema
result = convert_copybook_to_json(
    copybook_content=copybook_content,
    copybook_name="your_copybook.cpy",
    debug=False
)

if result["status"] == "success":
    print("JSON Schema:")
    print(result["json_string"])
    print(f"Record size: {result['record_size']} bytes")
    print(f"Field count: {result['field_count']}")
else:
    print(f"Error: {result['message']}")

Example

Input COBOL Copybook

01  EMPLOYEE-RECORD.
    05  EMP-ID          PIC 9(6).
    05  EMP-NAME        PIC X(30).
    05  EMP-SALARY      PIC 9(7)V99 COMP-3.
    05  EMP-DEPT        PIC X(10).
    05  EMP-ADDRESSES   OCCURS 3 TIMES.
        10  ADDR-TYPE   PIC X(10).
        10  ADDR-LINE1  PIC X(35).
        10  ADDR-LINE2  PIC X(35).

Output JSON Schema

The tool generates a comprehensive JSON schema that includes:

  • Field names and types
  • Data lengths and precision
  • Array structures for OCCURS clauses
  • Metadata about the original COBOL structure

API Reference

convert_copybook_to_json(copybook_content, copybook_name="copybook.cpy", debug=False)

Parameters:

  • copybook_content (str or list): COBOL copybook content as string or list of strings
  • copybook_name (str, optional): Name for the copybook (default: "copybook.cpy")
  • debug (bool, optional): Enable debug output (default: False)

Returns: Dictionary with the following keys:

  • status: "success" or "error"
  • json_string: Generated JSON schema (if successful)
  • record_size: Total record size in bytes
  • field_count: Number of fields processed
  • message: Error message (if failed)
  • traceback: Detailed error information (if debug enabled)

Requirements

  • Python 3.7 or higher
  • No external dependencies

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Use Cases

  • Mainframe Modernization: Convert legacy COBOL data structures for modern applications
  • Data Integration: Understand COBOL data formats for ETL processes
  • API Development: Generate schemas for APIs that interface with mainframe systems
  • Documentation: Create readable documentation of COBOL data structures

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

cobol_copybook_to_json-1.0.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cobol_copybook_to_json-1.0.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file cobol_copybook_to_json-1.0.0.tar.gz.

File metadata

  • Download URL: cobol_copybook_to_json-1.0.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for cobol_copybook_to_json-1.0.0.tar.gz
Algorithm Hash digest
SHA256 392ad88a9b7b06f04a3f84d8157addc36bb7fa806fd8a4b085669046eacd7bbc
MD5 63777a7c5355c6e9e9404276f541c4d4
BLAKE2b-256 0fce2a195b5b3ef4e50804be2603c21e312abad7e80bb0c41ce3f2937fe9ad6c

See more details on using hashes here.

File details

Details for the file cobol_copybook_to_json-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cobol_copybook_to_json-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7b43f3ea8dbf4e9213e163afb139ae081ce84c79b3031ee92da07030e76606b
MD5 5c73764781fda3801e74f1868b6f971e
BLAKE2b-256 6d2da4d31387c88834d99172ecc823267efc3c4706496819ad1208efa99a5e54

See more details on using hashes here.

Supported by

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