Formating json response from my own raw http server (data source using plugin "JSON")

Hi ! I’m a newbie grafana user and I try to “play” with it.
I wrote a simple python script using a standard http server (http.server).
On grafana side I created a data source pointing on localhost:5000.
It looks good since when I click on Save & test on Connections>Data sources dialog,
I got a “Data source is working” message and can see that my server receive a request on “/data”.
But then, when I try the explore data, my serveur receive a request on /data/metrics, it responds with a well serialized json (as I found some on fora) but grafana says No data.
Here is what looks like :

import http.server as HttpServer
import socketserver as SocketServer
import json,time,random

def json_server ( port,func ):
    class MyHandler ( HttpServer.BaseHTTPRequestHandler ):
        def do_GET ( self ):
            size = int( self.headers.get('Content-Length','-1') or '-1')
            data = None if size < 0 else self.rfile.read( size )
            code,resp = func( self.command,self.path,dict(self.headers),data )
            self.send_response( code )
            if resp is not None :
                resp = json.dumps( resp ).encode('utf8')
                self.send_header('Content-type','application/json')
                self.send_header('Content-Length',len( resp ))
                self.end_headers()
                self.wfile.write( resp )
        do_POST     = do_GET
        log_message = lambda *args : print( args[1]%tuple( args[2:] ))
    while True :
        SocketServer.TCPServer(('',port),MyHandler ).handle_request()

def func ( verb,path,head,body ):
    now  = int(time.time())
    data = [{"target": "Measure", "datapoints": [[11,now-3],[12,now-2],[13,now-1],[14,now]]}]
    return 200,data
json_server(5000,func)

And here are the logs :

"GET /data HTTP/1.1" 200 -                                 // Save & Test
"POST /data/metrics HTTP/1.1" 200 -                        // explore data

What am I doing wrong ?
Thank in advance !

welcome to forum @captainflam

probably would be best to naming your key value points explicitly unless you are worried about payload size? otherwise you could use infinity plugin with jsonata. here is one way you could do it with jsonata

https://try.jsonata.org/eJBvHQf21