Skip to main content

ChangeMan ZMF Plug-in for Zowe CLI - JSON received on Windows

  • April 10, 2024
  • 5 replies
  • 3 views

Stefano Antoniazzi

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

5 replies

Stefano Antoniazzi
  • Author
  • Participating Frequently
  • 15 replies
  • April 10, 2024

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...


  • Rocketeer
  • 19312 replies
  • April 10, 2024

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

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


Stefano Antoniazzi
  • Author
  • Participating Frequently
  • 15 replies
  • April 10, 2024

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.


  • Rocketeer
  • 19312 replies
  • April 10, 2024

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.


Stefano Antoniazzi
  • Author
  • Participating Frequently
  • 15 replies
  • April 10, 2024

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() .... 

😀