DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Modify JSON Data in Postgres and Hibernate 6
  • Exploring JSON Schema for Form Validation in Web Components
  • Datafaker Gen: Leveraging BigQuery Sink on Google Cloud Platform
  • Flexible Data Generation With Datafaker Gen

Trending

  • Tired of Spring Overhead? Try Dropwizard for Your Next Java Microservice
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  1. DZone
  2. Data Engineering
  3. Data
  4. Mule 4: Fixed Width Data to JSON Transformation Using CopyBook

Mule 4: Fixed Width Data to JSON Transformation Using CopyBook

Let's take a quick look at the fixed width data to JSON transformation using CopyBook. Explore the use case and the Mule flow.

By 
Murali Thuraka user avatar
Murali Thuraka
·
Updated Nov. 05, 18 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
23.2K Views

Join the DZone community and get the full member experience.

Join For Free

CopyBook is nothing but a section of code written in high-level language. It gives the schema structure and used in Mainframes for accessing the backend data into other applications. And it is originated from COBOL on IBM mainframe operating systems.

Use Case:

Transforming Fixed Width data to JSON format using COBOL CopyBook schema.

Mule Flow:

Step 1:

Configure the HTTP Listener with by giving hostname, port number and path along with this specify allowed methods (Optional) at the Advanced tab of HTTP connector.

Step 2:

Drag and drop the Set Payload from Mule Palette to validate the input payload using COBOL CopyBook Schema. And specify the schema path at MIME Type tab. In my case, it is like below:

Image title

From the above line:

schemas --> It is a directory

Hospital.ffd ---> It is CopyBook schema for validation.

Below is the Hospital.ffd schema for the reference:

form: COPYBOOK
id: 'HOSPITALSCOPYBOOK'
values: 
- name: 'HOSPITALS'
  values: 
  - name: 'BASIC-INFO'
    values: 
    - { name: 'NAME', type: String, length: 4 }
    - { name: 'ADDRESS', type: String, length: 4 }
    - { name: 'PHONE-NUMBER', type: Integer, length: 10, format: { justify: ZEROES, sign: UNSIGNED } }
    - { name: 'ADMIN', type: String, length: 4 }
- name: 'WARDS'
  values: 
  - name: 'BASIC-INFO'
    values: 
    - { name: 'NAME', type: String, length: 4 }
    - { name: 'ADDRESS', type: String, length: 4 }
    - { name: 'NUMBER', type: Integer, length: 10, format: { justify: ZEROES, sign: UNSIGNED } }
    - { name: 'ADMIN', type: String, length: 4 }

Step 3:

Drag and drop the Transform Message component for data format conversion.

Step 4:

Drag and drop the Logger component to log the resultant payload after validation.

Final Config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="84a3c2a5-c4d6-41bb-86c0-53a10f8bcf89" >
<http:listener-connection host="0.0.0.0" port="8082" />
</http:listener-config>
<flow name="hospital-flatfileFlow" doc:id="b232ad22-9adf-484a-82af-aa94dee96f72" >
<http:listener doc:name="Listener" doc:id="3689e2de-d1f3-4f80-8a8e-dc5a8a631870" config-ref="HTTP_Listener_config" path="/ff" allowedMethods="POST"/>
<set-payload value="#[payload]" doc:name="Set Payload" doc:id="3aafc767-ed26-4211-a6ca-f427ade9eb78" mimeType='application/flatfile; schemapath="schemas/Hospital.ffd"'/>
<ee:transform doc:name="Transform Message" doc:id="5dcfb492-24ec-4868-8b0b-d1e7393ff93d" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload map ( payload01 , indexOfPayload01 ) -> {
HospitalsCopyBook: {
Hospitals: {
"Basic-Info": {
Name: payload01.HOSPITALS."BASIC-INFO".NAME default "",
Address: payload01.HOSPITALS."BASIC-INFO".ADDRESS default "",
"Phone-Number": payload01.HOSPITALS."BASIC-INFO"."PHONE-NUMBER" default 0,
Admin: payload01.HOSPITALS."BASIC-INFO".ADMIN default ""
}
},
Wards: {
"Basic-Info": {
Name: payload01.WARDS."BASIC-INFO".NAME default "",
Address: payload01.WARDS."BASIC-INFO".ADDRESS default "",
Number: payload01.WARDS."BASIC-INFO".NUMBER default 0,
Admin: payload01.WARDS."BASIC-INFO".ADMIN default ""
}
}
}
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="df684849-aa1e-448d-8fbc-36b593ad2374" message="#[message.payload]"/>
</flow>
</mule>

Sample Input (POST):

Image title

Output:

Image title

Happy learning!

JSON Data (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Modify JSON Data in Postgres and Hibernate 6
  • Exploring JSON Schema for Form Validation in Web Components
  • Datafaker Gen: Leveraging BigQuery Sink on Google Cloud Platform
  • Flexible Data Generation With Datafaker Gen

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!