Creating JSON Schema from JSON data

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
sandhya.budhi
Premium Member
Premium Member
Posts: 18
Joined: Wed Nov 15, 2017 10:50 am

Creating JSON Schema from JSON data

Post by sandhya.budhi »

I wanted to do a REST call using a JSON file. The REST call should be made using the below JSON payload

Code: Select all

"Queue":[ 
 { 
      "YYYYYYYY",
       "AA",
       "07",
        "2017-11-14",
	false,
	"2017-11-14",
        15.2,
	"YYYYYYY",
	false,
	"SPACER",
	false,
        "07",
	"Japan export",
	"C",
        0.000,
	"NONE",
	"YYYYYY",
	false,
	false
},
{
       "XXXXXX",
       "AA",
       "07",
        "2017-11-14",
	false,
	"2017-11-14",
        15.2,
	"XXXXXXX",
	false,
	"SPACER",
	false,
        "07",
	"Japan export",
	"C",
        0.000,
	"NONE",
	"XXXXXX",
	false,
	false 
  }
]

I am creating the schema for JSON composer stage and it is giving me an error message the schema is invalid. I am looking some help in creating the JSON schema for having a JSON object inside an JSON array.

Code: Select all

  "type": "array",
  "items":[
    "type": "object",
      {
        "name": "string"
      },
      {
        "address": "string"
      },
      {
        "area": "string"
      },
      {
        "dob": "string"
      },
      {
        "Status": "boolean"
      },
      {
        "rec": "string"
      },
      {
        "counter": "number"
      },
      {
        "desig": "string"
      },
      {
        "worktool": "boolean"
      },
      {
        "desc": "string"
      },
      {
        "reman": "boolean"
      },
      {
        "area2": "string"
      },
      {
        "req_reason": "string"
      },
      {
        "suspend": "string"
      },
      {
        "seqno": "number"
      },
      {
        "crb": "string"
      },
      {
        "dcc": "string"
      },
      {
        "base": "boolean"
      },
      {
        "deleted": "boolean"
      }
]
Thanks,
Sandhya
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

<added code tags>
-craig

"You can never have too many knives" -- Logan Nine Fingers
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

I'm not an expert on the "standard" itself, but based on all the JSON payloads that I've seen, it is invalid. For those values to be outlined as such, they need tags.....

Try opening it with an editor or tool that supports JSON formatting. ( One that I find very useful is a plugin to Firefox, https://jsonview.com )

Here is a more typical JSON structure. Note how the tags are directly "in" the data. In the Stage, you import "the" JSON document itself --- the schema is crafted dynamically from your "real" sample:

Code: Select all

{

    "Supplier": "DEF Manufacturing",
    "Contact": "Ravi Sharma",
    "Region": "East",
    "Products": [
        {
            "name": "Widget",
            "description": "3x3 wooden cube",
            "Product Code": "753"
        },
        {
            "name": "thing",
            "description": "straight piece of stainless steel",
            "Product Code": "717"
        },
        {
            "name": "Widget2",
            "description": "3x3 wooden cube",
            "Product Code": "753"
        },
        {
            "name": "thing3",
            "description": "straight piece of stainless steel",
            "Product Code": "717"
        },
        {
            "name": "Widget3",
            "description": "3x3 wooden cube",
            "Product Code": "753"
        },
        {
            "name": "thing3",
            "description": "straight piece of stainless steel",
            "Product Code": "717"
        }
    ]

}
Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
sandhya.budhi
Premium Member
Premium Member
Posts: 18
Joined: Wed Nov 15, 2017 10:50 am

Post by sandhya.budhi »

Thanks for the response. I managed to get the JSON schema correct for JSON payload.

Is there any way I can verify the REST call made through Heirarchical stage and how it passes the arguments to REST API like mentioned below

Code: Select all

PUT https://example.com HTTP/1.1 
Authorization: Basic XXXXXXXXXXXXXXX== 
content-type: application/json 

[{ 
       "part": "123456", 
          "type": "AA", 
       "area": "XX"
 
}] 
I am trying to make the REST call and it is giving me the error - CDIER0916E: The REST step found a non-2xx status code in an HTTP response

I wanted to check whether I am passing the parameters passed to PUT method correctly
Thanks,
Sandhya
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Try the logs settings at the stage level before you enter the assembly. They "may" help here.....they are voluminous.....their location will be written i to the dslog near the start of the job.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
sandhya.budhi
Premium Member
Premium Member
Posts: 18
Joined: Wed Nov 15, 2017 10:50 am

Post by sandhya.budhi »

I tried logs settings at stage level but it is not capturing the logs as expected. I reached my support team and they are checking at their end. But I worked on the error and I received response back to REST call though not successful. Waiting for the support tream to get back on the logs.
Thanks,
Sandhya
Post Reply