Skip to main content

Hi, 

I'm testing ChangeMan REST API functions from zmf plug in for zowe cli  using the sample from

 Trigger DEMOTE outside the mainframe using Jenkins Pipeline 

I've a problem with returned json.

Just executing the command

 zowe zmf get component -c "PYTCC001" -t "COB" -p "BKA 000435" --zmf-profile "zmfx" > K:/projectsout/mainframe/cmnrestsample/testhttp.json

from a Windows Command line (Powershell, cmd, ...) I get a text file with many "dirt" chars.

I've tried also a direct connection to Tomcat using only http port but nothing Changes.

Returned json is something like this where expected json fields are surrounded by these wrong chars:

Somebody has an idea where to investigate?

Thanks.


#problem
#JSON
#ChangeManZMF
#CLI
#REST
#ZMF

Hi, 

I'm testing ChangeMan REST API functions from zmf plug in for zowe cli  using the sample from

 Trigger DEMOTE outside the mainframe using Jenkins Pipeline 

I've a problem with returned json.

Just executing the command

 zowe zmf get component -c "PYTCC001" -t "COB" -p "BKA 000435" --zmf-profile "zmfx" > K:/projectsout/mainframe/cmnrestsample/testhttp.json

from a Windows Command line (Powershell, cmd, ...) I get a text file with many "dirt" chars.

I've tried also a direct connection to Tomcat using only http port but nothing Changes.

Returned json is something like this where expected json fields are surrounded by these wrong chars:

Somebody has an idea where to investigate?

Thanks.


#problem
#JSON
#ChangeManZMF
#CLI
#REST
#ZMF

It seems that they are related to ANSI Colors in standard Windows shell...


It seems that they are related to ANSI Colors in standard Windows shell...

Using python, json.load() or json.loads() should unescape the data.


Using python, json.load() or json.loads() should unescape the data.

Hi David, I've written here after getting exceptions from json.loads()

At the end I've found that it may be solved just adding --response-format-json (short : --rfj) option to command.

So my full command becomes

zowe zmf get component -c "PYTCC001" -t "COB" -p "BKA 000435" --rfj --zmf-profile "zmfx" > K:/projectsout/mainframe/cmnrestsample/testhttprfj.json

In this way I get a clean json because the "windows console colours escaped content" is assigned to property "stdout" and the json received has a specific "data" property that is a "clean" object

{
  "success": true,
  "exitCode": 0,
  "message": "",
  "stdout": "\\u001b[35m{
  ....
  ....
  "stderr": "",
  "data": {
    "message": "CMN8700I - LIST service completed",
    "reasonCode": "8700",
    "returnCode": "00",
    "result": [
      {
        "applName": "BKA",
        "baseDateLastModified": "20230919",
        ...
             }
    ]
  }
}
  

And also using json.loads() now it's ok without exceptions.


Hi David, I've written here after getting exceptions from json.loads()

At the end I've found that it may be solved just adding --response-format-json (short : --rfj) option to command.

So my full command becomes

zowe zmf get component -c "PYTCC001" -t "COB" -p "BKA 000435" --rfj --zmf-profile "zmfx" > K:/projectsout/mainframe/cmnrestsample/testhttprfj.json

In this way I get a clean json because the "windows console colours escaped content" is assigned to property "stdout" and the json received has a specific "data" property that is a "clean" object

{
  "success": true,
  "exitCode": 0,
  "message": "",
  "stdout": "\\u001b[35m{
  ....
  ....
  "stderr": "",
  "data": {
    "message": "CMN8700I - LIST service completed",
    "reasonCode": "8700",
    "returnCode": "00",
    "result": [
      {
        "applName": "BKA",
        "baseDateLastModified": "20230919",
        ...
             }
    ]
  }
}
  

And also using json.loads() now it's ok without exceptions.

json.load() takes in an input file whilst json.loads() takes in a string.


json.load() takes in an input file whilst json.loads() takes in a string.

Yes, of course.

I've tried both.

The sample in this post (as the original sample) uses a file and so a json.load().

But usually I run with

myCommandCompleted = subprocess.run( myCommandString, text=True, capture_output=True)
so I get directly the json from 
myCommandCompleted.stdout

and I may use json.loads() .... 

😀