0

I'm writing a VB.Net application with an API to send values to a datasource. My JSON output is made with NewtonSoft.Json like the following:

{
    "Id": null,
    "Name": "Werkkaart_tests",
    "ExternalId": "Werkkaart_test",
    "Headers": null,
    "Rows": null,
    "NewRows": ["val 1, val 2, val 3, val 4"],
    "DeletedRows": null,
    "CompanyId": 1111,
    "IntegrationKey": "lsfjlsfjlsfj3987"
}

With a PUT request I can update the datasource. The model schema of the JSON is like this:

{
  "Id": "",
  "Name": "",
  "ExternalId": "",
  "Headers": [
    {
      "Name": "",
      "DisplayAt": ""
    }
  ],
  "Rows": [
    "Array[string]"
  ],
  "NewRows": [
    "Array[string]"
  ],
  "DeletedRows": [
    "Array[string]"
  ],
  "CompanyId": 0,
  "IntegrationKey": ""
}

The datasource has 4 columns named col1, col2, col3 and col4. To add new rows to the datasource I have to make an Array of String in NewRows.

When I send my JSON-string columns 1 till 4 are filled with the following values:

col1 col2 col3 col4
val 1 val 2

What I want is the following:

col1 col2 col3 col4
val1 val2 val3 val4

I tried placing single quotes around my values, but that doesn't work. I also tried the following:

"NewRows": ["val 1", "val 2", "val 3", "val 4"],

but the I get the following result:

col1 col2 col3 col4
val1
val2
val3
val4

Here's the vb code:

Dim src As New DSS.DataSource
Dim values As List(Of String) = New List(Of String)

values.Add("val 1") 
values.Add("val 2")
values.Add("val 3")

src.Name = "SourceName"
src.ExternalId = "Source_ExtID"

Dim newRowsString As String = String.Join(", ", values)
src.NewRows = New List(Of String) From {newRowsString} 

Dim json As String = JsonConvert.SerializeObject(src)
Console.WriteLine(json)
8
  • 1
    It would help if you provide your vb code Commented Sep 21, 2023 at 18:57
  • 1
    "val 1, val 2, val 3, val 4" <-- this is a single array item as JSON is concerned Commented Sep 21, 2023 at 19:18
  • You're mixing horizontal vs vertical. Your json attributes is horizontal data. Your Array values are vertical data. i.e. Array items are 1 records each. attributes - 1 field each Commented Sep 21, 2023 at 19:20
  • When I do a PUT-request like this: "val 1, val 2, val 3, val 4" it ffiling up the datasource like val | 1 | val | 2. I would suggest that it would be like val 1 | val 2 | val 3 | val 4. Commented Sep 21, 2023 at 19:26
  • 1
    Is the new row supposed be an array itself? i.e. should the resulting json be "NewRows" : [["val 1", "val 2", "val 3", "val 4"]]? Commented Sep 22, 2023 at 18:35

1 Answer 1

0

Note that the type of NewRows is denoted as "Array[String]". But you are providing a scalar string i.e. "val 1, val 2, val 3, val 4". You should provide the values as separate strings inside an array, so that NewRows is an array of arrays, i.e. the resulting json should be "NewRows" : [["val 1", "val 2", "val 3", "val 4"]].

Each element in the outer array is a different row, each element of the inner array is a separate column within that particular row.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.