Get JSON data from influxdb 2.0

Hi @dan-moran ,

I came up with this solution which meets my requirements.

Here is the code which is giving me a json response with python library -

from db.db_conf import INFLUX_CLIENT
from conf.settings import DB_ORG
import pandas as pd

query = '''
from(bucket: "SENSOR_DB") 
    |> range(start: 2020-06-30T15:13:17.056Z, stop: 2021-06-30T16:13:17.056Z) 
    |> filter(fn: (r) => r["_measurement"] == "sensor_data_fb9a8") 
    |> keep(columns: ["_time", "_field", "_value"])
    |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value") 
    |> yield()
    '''
df = INFLUX_CLIENT.query_api().query_data_frame(query, org=DB_ORG)
print(df.to_json(orient='records'))

Which is giving result like -

[{
	"_time": 1614253728439,
	"OriginalTime": 1614253719434,
	"assetId": "0",
	"featureName": "testFeature",
	"sensorId": "601804",
	"sensortest01": "50",
	"sensortest02": "50"
}, {
	"_time": 1614254044553,
	"OriginalTime": 1614254035648,
	"assetId": "0",
	"featureName": "testFeature",
	"sensorId": "601805",
	"sensortest01": "jhghj",
	"sensortest02": "ghjgjgh"
}]

It might help others who are looking for this kinf of solution.