0

Hi I am trying to consume some data from a api using c# and .Net 8.

I am receiving the data in JSON format however the JSON format does not seem to be correct.

Below is the Sample format of Json format

{   "data": {"object1": {"id": "abcde","name": "xyz","labels": {"app1": "app1", "app2": "app2"},"cid": "1234567890","cn": "cnvalue"}}}
{   "data": {"object1": {"id": "abcde1","name": "xyz1","labels": {"app1": "app11","app2": "app21"},"cid": "1234567890","cn": "cnvalue"}}}

While trying to deserializing the JSON object I am getting the below error System.Text.Json.JsonException: ''{' is invalid after a single JSON value. Expected end of data. Path: $ | LineNumber: 1 | BytePositionInLine: 0.'

Any help will be appreciated. Please do let us know if you need any additional information.

4
  • That's not valid json. It's probably "jsonlines". Parse line by line. Commented Dec 4, 2024 at 12:11
  • 1
    It is the JSON lines format, which means multiple JSONs separated by newlines. Each JSON is formatted on a single line. You need to split the input on lines and parse each line as an individual JSON. Commented Dec 4, 2024 at 12:11
  • There's no "JSON Lines" format, that's an attempt by someone to hijack the decade(s)-old practice of streaming JSON by storing one unindented JSON object per line by imitating Douglas Crockford's original JSON site. It's neither a standard nor is it related in any way to JSON.org. You'll find the exact same thing called ND-JSON, JSON-Lines etc. The only true standard is json-seq which doesn't use newlines to separate records Commented Dec 4, 2024 at 14:27
  • 1
    in .NET 9 jsonlines format is supported, see parsing text that is a sequence of JSON objects without enclosing brackets (there is no root object) in .NET?. Before .NET 9 see this answer by Nathan. Commented Dec 4, 2024 at 14:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.