Making C# webapi (gateway to OracleDB), "datapoints" JSON difficulties

Just in case you need to fiddle with C# as “middle-man” bringing data to Grafana. I struggled a lot with \Query “datapoints” element. To save some overhead data, JSON is not having property names for metric value and unix timestamp. Dropping property names with standard C# WebAPI seriliazition was not easy. (If you know better way, shout). I Tried Tuple, Dictionary, key value…

Only solution for datapoints was creating a list in a list with doubles. Timestamp value is ok, with extra decimal (123.0).

    /// <summary>
    /// Data element name
    /// </summary>
    public String target { get; set; }
    /// <summary>
    /// Due the Grafana timeserie data format, without property name, have to do <list><list>
    /// </summary>
    public List<List<double>> datapoints { get; set; }

Standard serialization by VS2017 C# WebAPI, produces JSON what works ok. Naturally, filling the list-list is not so elegant.

I just wanted to share this, I spend some (wasted) time with this.

Hi,

Thank you for the information. I’m sure others will find this useful.

Marcus

In my JSON “noobiness” :slight_smile: To figure out these multiple [[{}][]]}] arrays(without element names) to correctly deserialize C# objects.

Found these great free online tools:
http://json2csharp.com/
https://jsonutils.com/

Without these automatic code generator tools, you are looking for pain