Send JSON log to HTTP API

I’m trying to upload logs with json format.

So far I have tried:

import requests
headers = {'Content-type': 'application/json'}
data='{ "streams": [ { "labels": "{source=\"JSON\",job=\"simpleJsonJob\", host=\"SimpleHost\"}", "entries": [{ "timestamp": "1570818238000000000", "line": "TEST!" }] } ] }'
response=requests.post("https://DOMAIN/loki/api/v1/push", headers=headers, data=data)
print (str(response.content))

Data structure taken from: can't push correctly json data to Loki · Issue #478 · grafana/loki · GitHub which according to the issue it should work.

But I get:

b’loghttp.PushRequest.Streams: *loghttp.Stream: ReadObjectCB: object not ended with }, error found in #10 byte of …|{source=“JSON”,job="|…, bigger context …|{ “streams”: [ { “labels”: “{source=“JSON”,job=“simpleJsonJob”, host=“SimpleHost”}”, "en|…\n’

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.