Try to run rpc-shell-execute for any CLI command.
Original Message:
Sent: 07-31-2024 12:30
From: Jessica Garrison
Subject: Question on JSON and the Junos CLI
Example from my device.
[vrf:none] jcluser@re0:~$ curl http://username:password@localhost:3000/rpc/get-system-information -H "Accept: application/json"
{
"system-information" : [
{
"hardware-model" : [
{
"data" : "qfx5130-32cd"
}
],
"os-name" : [
{
"data" : "junos-qfx"
}
],
"os-version" : [
{
"data" : "21.4R2.14-EVO"
}
],
"serial-number" : [
{
"data" : "123456789"
}
],
"host-name" : [
{
"data" : "switch04-qfx5130-32cd"
}
]
}
]
}
------------------------------
Jessica Garrison
Original Message:
Sent: 07-30-2024 18:00
From: asharp
Subject: Question on JSON and the Junos CLI
Maybe try with an Accept: application/json
or switch to RPC instead of executing cli from the shell.
<rpc><get-system-information format="json"/></rpc>
Regards
------------------------------
Andy Sharp
Original Message:
Sent: 07-30-2024 13:11
From: Yan Gorelik
Subject: Question on JSON and the Junos CLI
Hi Andy
I am polling Juniper device EX-4550 v15.1 via Cisco Network Orchestrator, which talks to device using RPC. The equivalent curl query looks like this:
ygorelik$ curl -X POST http://localhost:8090/restconf/operations/devices/device=junos-ex-map-1/rpc/rpc-request-shell-execute/request-shell-execute -d '{"command": "cli show version all-members"}' -u "admin:admin" -H "Content-type: application/yang-data+json"
{
"junos-rpc:output": {
"output": "fpc0:\n--------------------------------------------------------------------------\nHostname: JUNOS-EX-1\nModel: ex4550-32f\nJunos: 15.1R7-S13\nJUNOS EX Software Suite [15.1R7-S13]\nJUNOS FIPS mode utilities [15.1R7-S13]\nJUNOS Online Documentation [15.1R7-S13]\nJUNOS EX 4500 Software Suite [15.1R7-S13]\nJUNOS Web Management Platform Package [15.1R7-S13]"
}
}
As you can see, I am getting JSON response as expected, but the "output" is returned as Juniper-style string.
My question: how can I get the output as JSON encoded string? Or how can I convert the J-stile string to JSON in my application?
Note, that RPC does not accept piping the output to "display json", which works perfectly well directly on the device. It could be that some RPC configuration parameter must be set to get the output as JSON formatted string, but I am not aware of such method.
I really appreciate your prompt response!
------------------------------
Yan Gorelik
Original Message:
Sent: 03-30-2024 07:16
From: asharp
Subject: Question on JSON and the Junos CLI
Correct, it is still mgd that is performing the conversion of the RPC request via either NETCONF or REST as JSON.
Regards.
------------------------------
Andy Sharp
Original Message:
Sent: 03-29-2024 08:02
From: djadhav
Subject: Question on JSON and the Junos CLI
Hi.
Below I have logged into the Junos CLI and request some information in JSON format.
lab@vmx1> show system information | display json
{
"system-information" : [
{
"hardware-model" : [
{
"data" : "vmx"
}
],
"os-name" : [
{
"data" : "junos"
}
],
"os-version" : [
{
"data" : "18.3R1.9"
}
],
"serial-number" : [
{
"data" : "VM5C8C145200"
}
],
"host-name" : [
{
"data" : "vmx1"
}
]
}
]
}
My understanding is that Junos responds to the operational command in XML, which is then converted by the CLI into JSON.
Now I'm retrieving the same JSON information, but this time from my management station using RESTful messages:
[lab@desktop ~]$ curl http://10.10.1.1:3000/rpc/get-system-information -u "lab:lab123" -H "Accept: application/json"
{
"system-information" : [
{
"hardware-model" : [
{
"data" : "vmx"
}
],
"os-name" : [
{
"data" : "junos"
}
],
"os-version" : [
{
"data" : "18.3R1.9"
}
],
"serial-number" : [
{
"data" : "VM5C8C145200"
}
],
"host-name" : [
{
"data" : "vmx1"
}
]
}
]
}
My question is: Who is doing the XML->JSON conversion here? Is it still the Junos CLI?
Thanks,
Deepak
Juniper Business Use Only