Need help on creating JSON file.

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
BrahmaAcc
Participant
Posts: 3
Joined: Tue Aug 02, 2016 8:19 am

Need help on creating JSON file.

Post by BrahmaAcc »

Hi All,

I am new to JSON files.

I have task to create a JSON file from pipe (|) delimited file.Below is the sample data and expected output.

My Job Design is as below:

SeqFileStage--> Hierarchical Data Stage

Sample Input:

column1|column2|column3|column4|column5|column6|column7|column8
1000|ABCDEF|HIPID|30000000000002|NONPB|false|false|false
1000|ABCDEF|HIPID|30000000000003|NONPB|false|false|false
1000|ABCDEF|HIPID|30000000000004|NONPB|false|false|false
1000|ABCDEF|HIPID|31000000000002|NONPB|false|false|false


Expected Output:

Code: Select all

{
        "column1": "1000",
        "column2": "ABCDEF",
        "plans": [
            {
                "column3": "HIPID",
                "column4": "30000000000002",
                "column5": "NONPB",
                "column6": false,
                "column7": false,
                "column8": false
            },
            {
                "column3": "HIPID",
                "column4": "30000000000003",
                "column5": "NONPB",
                "column6": false,
                "column7": false,
                "column8": false
            },
            {
                "column3": "HIPID",
                "column4": "30000000000004",
                "column5": "NONPB",
                "column6": false,
                "column7": false,
                "column8": false
            },
            {
                "column3": "HIPID",
                "column4": "31000000000002",
                "column5": "NONPB",
                "column6": false,
                "column7": false,
                "column8": false
            }
        ]
    }
Does Hierarchical Data Stage has the capacity to create a JSON file ? or
Does Hierarchical Data Stage is created/programmed in such a way where it can handle array of multiple looping records.

Thanks,
Brahma
Brahma
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Welcome aboard. The short answer is yes.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
BrahmaAcc
Participant
Posts: 3
Joined: Tue Aug 02, 2016 8:19 am

Post by BrahmaAcc »

Hi Ray,

Thanks for your reply.

As of now, my job is not able to create expected json file.

For my example , Could you please let me know how to configure "Hierarchical Data Stage" so that it can create a .json file with multiple loops in it.

Could you please put some light on it..

Thanks,
Brahma
Brahma
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

There's some official IBM documentation here on both reading and composing JSON with the stage.
-craig

"You can never have too many knives" -- Logan Nine Fingers
BrahmaAcc
Participant
Posts: 3
Joined: Tue Aug 02, 2016 8:19 am

Post by BrahmaAcc »

Hi Craig,

Thanks for IBM example link.

I have tried example given by IBM too . In the given IBM example we have two input files to create .json file (using HJOIN ),but in my case I have only one delimited file ( For key column I have multiple rows -- have a look at my example data) .This is where I am not able to configure Hierarchical Data Stage to create a JSON file. Now I need help from you people , for my example, steps to configure Hierarchical Data Stage "ASSEMBLY" so that we can create a ".JSON" file.

:cry:

Thanks,
Brahma
Brahma
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Its not easy, and starting with JSON can complicate things. When JSON is read into the library manager, it mocks up an xml xsd for it (simpler to learn the stage the first time using xml). So...in your case, you have hopefully imported the exact target JSON as you have specified up above. Once you do that, the contained repeating items will become a "list" (blue icon if you expand inside the library manager). That "list" gets mapped to multiple rows.

Writing is more difficult than reading. One thing I would suggest is to put the JSON above into a file and work on reading it with the Stage, that might give you a feel for how the Assembly editor works.

You will map that "list" to an output link to generate various rows, one for each repeating section of the JSON.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
Post Reply