How to get restconf result in json without namespace reference in the output

when i execute below restconf request with accept application/yang-data+json
http://localhost:30742/restconf/data/data_container:data
I am getting below result

{
    "data_container:data": [
        {
            "id": "1"
        }
    ]
}

how can I escape the namespace data_container from the response?. is there any request parameter?

I’m afraid you cannot, there is no such parameter. This is mandated by the JSON Encoding RFC, namespace-qualified member name must be used for all members of a top-level JSON object.

But you can post-process the result; if you are running the request from a command line, you can pass the result either to a tool such as the powerful JSON processor jq

your_request | jq 'with_entries(.key |= (split(":") | .[1]))'

or to a Python “one-liner” like

your_request | python -c 'import json; import sys; \
json.dump({k.split(":")[1]: v for k, v in json.load(sys.stdin).items()}, \
fp=sys.stdout, indent=2)'

If you need to do that from within your code, I’m pretty sure your environment contains libraries that allow you to do the same.

1 Like

thanks for confirming.