We are using visual cobol 2.3, framework 4.5. I need to send out a json file. We don't currently work with json so I am not sure what I am doing. I seen there is a json generate statement in cobol upgrades, but upgrading is not an option for us right now. I guess I envision this to have a text file that we would run a program over to convert to json. How would the text file need set up? What statements/libraries would be needed? Thanks!
We are using visual cobol 2.3, framework 4.5. I need to send out a json file. We don't currently work with json so I am not sure what I am doing. I seen there is a json generate statement in cobol upgrades, but upgrading is not an option for us right now. I guess I envision this to have a text file that we would run a program over to convert to json. How would the text file need set up? What statements/libraries would be needed? Thanks!
As you mentioned Framework 4.5 am I correct in thinking that you are working with a .NET application ? If you are, an option would be to try using Json.NET.
As you mentioned Framework 4.5 am I correct in thinking that you are working with a .NET application ? If you are, an option would be to try using Json.NET.
Also
Have you considered using jq?
To transform a text file into a json file.
https://stedolan.github.io/jq/
This has a download for windows.
This is an example jq script.
<>> texttojson.jq
# # run this command with input from hostnamectl # hostnamectl | jq -n -R -f texttojson.jq # or add jq json query # hostnamectl | jq -n -R -f texttojson.jq | jq .thiscomputer.hostnamectl["\\"CPE OS Name\\""] # "cpe:/o:redhat:enterprise_linux:8.2:GA" # or using textfile input # hostnamectl >hostnamectl.txt # jq -n -R -f texttojson.jq hostnamectl.txt >texttojson.json # jq .thiscomputer.hostnamectl["\\"CPE OS Name\\""] texttojson.json # "cpe:/o:redhat:enterprise_linux:8.2:GA" # # # {"thiscomputer": {"hostnamectl": [ inputs | gsub("^\\\\s |\\\\s $";"") | split(": ") | {(.[0]): .[1]} ] | add } }
Turns this text output, from the unix hostnamectl command
<>>
$ hostnamectl Static hostname: tonyt-rhel8-01.microfocus.aws.lab Icon name: computer-vm Chassis: vm Machine ID: 34de6610bf0046b399122b1892d203b1 Boot ID: 8e606f7c2298409db868254128bdf606 Virtualization: xen Operating System: Red Hat Enterprise Linux 8.2 (Ootpa) CPE OS Name: cpe:/o:redhat:enterprise_linux:8.2:GA Kernel: Linux 4.18.0-193.el8.x86_64 Architecture: x86-64 $
Into this, using this command
$ hostnamectl | jq -n -R -f texttojson.jq { "thiscomputer": { "hostnamectl": { "Static hostname": "tonyt-rhel8-01.microfocus.aws.lab", "Icon name": "computer-vm", "Chassis": "vm", "Machine ID": "34de6610bf0046b399122b1892d203b1", "Boot ID": "8e606f7c2298409db868254128bdf606", "Virtualization": "xen", "Operating System": "Red Hat Enterprise Linux 8.2 (Ootpa)", "CPE OS Name": "cpe:/o:redhat:enterprise_linux:8.2:GA", "Kernel": "Linux 4.18.0-193.el8.x86_64", "Architecture": "x86-64" } } } $
The thing that does the main work is the split(“: “)
You could comment delimit the file output by cobol and use split(“, “)
Once you have many json files you can use jq to mangle/merge them together it is very powerful.
Further reading
https://thoughtbot.com/blog/jq-is-sed-for-json
Sign up
Already have an account? Login
Welcome to the Rocket Forum!
Please log in or register:
Employee Login | Registration Member Login | RegistrationEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.