cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2330
Views
5
Helpful
5
Replies

yang-patch with JSON data

tcragg1
Cisco Employee
Cisco Employee

I've been trying to use the yang-patch method with JSON data to write changes to device configurations in NSO, but have been having trouble making it work. Below is the JSON data I am trying to send to /restconf/data to configure an IOS device:

 

{
  "ietf-yang-patch:yang-patch": {
    "patch-id": "test-patch",
    "edit": [
      {
        "edit-id": "test1",
        "operation": "merge",
        "target": "/tailf-ncs:devices/device=hs4-inf-p-rr01/config/tailf-ned-cisco-ios:interface/GigabitEthernet0%2F0%2F5.51",
        "value": {
          "tailf-ned-cisco-ios:GigabitEthernet": [
            {
              "name": "0/0/5.51",
              "description": "Test",
            }
          ]
        }
      }
    ]
  }
}

This just returns a malformed-message error. When I attempt the same thing using XML with the following data, it works correctly:

<yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
  <patch-id>test-patch</patch-id>
  <edit>
    <edit-id>test1</edit-id>
    <operation>merge</operation>
    <target>/tailf-ncs:devices/device=hs4-inf-p-rr01/config/tailf-ned-cisco-ios:interface/GigabitEthernet=0%2F0%2F5.51</target>
    <value>
      <GigabitEthernet xmlns="urn:ios"  xmlns:ios="urn:ios"  xmlns:ncs="http://tail-f.com/ns/ncs">
        <name>0/0/5.51</name>
        <description>Test</description>
      </GigabitEthernet>
    </value>
  </edit>
</yang-patch>

Can anyone advise what I am doing wrong with the JSON?

5 Replies 5

rogaglia
Cisco Employee
Cisco Employee

Could it be that:

"description": "Test",   <--- remove final comma

Unfortunately not, I still just get a malformed message error if I remove that comma and re-try.

perander
Cisco Employee
Cisco Employee
I could reproduce this with a toy example. It seems to be bug and I filed a ticket for it.

Was this ever fixed? Seeing the same problem on 5.3.2.4.

chopps
Level 1
Level 1

I realize this is 5 years later so probably not helpful, but I landed here searching for help with something else and noticed what might have been your problem.. In your JSON example, your target value is missing an `=` between the interface node name "GigabiteEthernet" and the key "0/0/5.51". In your XML example (which you said works) you did include the `=` sign.

Polls
AI-powered tools for network troubleshooting are likely to be part of everyone’s workflow sooner or later. What is the single biggest challenge or concern you see with adopting these tools in your organization?