Quantcast
Channel: Support & Bugs - Matomo forums
Viewing all articles
Browse latest Browse all 5981

Json response format incoherence

$
0
0

To make a long story short, let’s consider, single endpoint, single idSite=1, and simple response data.

It looks more or less like that, if there are some data:

{
    "key1": 1,
    "key2": 2
}

otherwise:

{
    "key1": 0,
    "key2": 0
}

In case of plural idSite=1,2, and if in both cases there are some data:

{
    "1": {
        "key11": 11,
        "key12": 12
    },
    "2": {
        "key21": 21,
        "key22": 22
    },
}

but In case of plural idSite=1,2, and in case if some data are missing:

{
    "1": {
        "key11": 11,
        "key12": 12
    },
    "2": [],
}

Our microservice is written in php, but recently, due to our intention to increase the performance, we decided to rewrite it in golang.
php doesn’t have an issue with the last json response snippet, but compiled, statically typed golang - that’s another story.
In case of such an incoherent value data types, you have to resort to unsightly solutions - in my case, parsing json response, and replacing [] with {} to be able to convert json string to the map[string] type - the map[string] values types has to be the same type for all its keys.
For a single idSite you can deal with it, but when you parse a json string of 100, 200, 300,… idSites data, it starts making a difference.

So my question for Matomo Team is if it is possible to make a fix of the format of json response containing non existing data.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5981

Trending Articles