JSON API datasource returning "Fields have different lengths" error

When querying a datasource that returns the following structure, the JSON API give the “Fields have different lengths” when set the field JSONPath selectors to “.devices[*].name" and ".devices[*].swVersion”

{
“request”: {
“url”: “api/datasources/proxy/6/topology/devices?detail=1&fields=name%2CswVersion%2CipAddress%2CgatewayUser”,
“method”: “GET”,
“hideFromInspector”: false
},
“response”: {
“devices”: [
{
“swVersion”: “6.60A.274”,
“ipAddress”: “192.168.200.30”,
“name”: “MP114_v2”,
“id”: 213,
“sbcInfo”: {
“gatewayUser”: “Admin”
}
},

Any suggestions on what might be the problem with the selectors?

Hi, I’m the author of this plugin. I’m able to query the data you provided:

Most likely, the error you’re getting means that one of the devices are missing either the name or the swVersion. Detecting null values is currently not possible.

Good to know.

I bet that’s the problem. I only gave you the first returned object in the array.

The second object does have a null value for the “swVersion”.

{

"devices": [

    {

        "swVersion": "6.60A.274",

        "ipAddress": "192.168.200.30",

        "name": "MP114_v2",

        "id": 213,

        "sbcInfo": {

            "gatewayUser": "Admin",

            "gatewayPassword": ""

        }

    },

    {

        "swVersion": null,

        "ipAddress": null,

        "name": "RC_M500",

        "id": 3635,

        "sbcInfo": {

            "gatewayUser": "BHNAdmin",

            "gatewayPassword": ""

        }

    },

Is there anyway to overcome this in the module? It isn’t possible to filter that out in the REST API call.

Would it be possible to put a check in the module to convert null to an empty string “”?

It’s a trickier problem than it may seem unfortunately. The problem is that if a property doesn’t exist, JSON Path ignores it.

To illustrate the problem, here are three separate queries:

Since name exists in each object, no problem. You get three strings back.

But with age, the JSON Path only find two occurrences:

In fact, if the property existed, but was null, it would also work:

Since each JSON Path query runs separately from the others, I have no way of knowing which age was missing.

Actually, looking at your example again, I see that it does have a null value, meaning it should work. I’ll get back after I’ve tested it.

Just verified that it works if there are null values rather than missing values.

It’s not working for me.

Not sure what the problem is. I should be running the latest version.

I see the issue. There is an object in the returned array that is missing the parameter.

I’ll see if i can create a query to filter that out. Many thanks for your responses.

{

        "swVersion": null,

        "ipAddress": "172.16.1.5",

        "name": "Test_Device_5",

        "id": 3832,

        "sbcInfo": {

            "gatewayUser": "Admin",

            "gatewayPassword": ""

        }

    },

    {

        "ipAddress": "10.1.1.145",

        "name": "non-acl",

        "id": 3833

    },

No worries at all. Thanks for using the plugin!

If you run into any issues down the road though, I’m more responsive on the GitHub project page.

Perfect, thank you! I have it working now. I was able to apply a filter to the REST API server to remove the objects that have the missing parameter.

The plugin is working very well. Thanks again.

1 Like