Questions tagged [jsonelement]

14 questions
5
votes
1 answer

C# JsonElement to string without formatting

I need to convert a JsonElement to string but without any carriage return, tabs or spaces. A simple ToString() works but leaves those in: data.ToString() Results: "{\r\n "Field1": "Value1",\r\n "Field2": "Value2"\r\n }" Looking…
Xaphann
  • 3,195
  • 10
  • 42
  • 70
3
votes
2 answers

Equivalent of JArray.FromObject() in .Net5?

We have a project which using System.Text.Json in .NET 5 instead of Newtonsoft JObject. Using Newtonsoft, it is pretty easy to replace dynamic JSON data e.g. as shown below: siteDataObject["student"] =…
Carrie Kaski
  • 133
  • 7
2
votes
0 answers

JsonElement Parameter has valuekind undefined even after passing data?

I created a method that takes in a JSONElement parameter. The problem is that whenever I execute the method and pass it a json object, the parameter is always of value undefined. Why is this happening? The following is the method that I am trying to…
1
vote
1 answer

C# Object - get properties from json within the object

My HTTP response data includes a field that is structured as a Dictionary. Accessing the Object in debug mode shows me what I expect to see, i.e. ValueKind = Object: { "someProp" : "someValue", "anotherProp" : "anotherValue" .. } =>…
ISquared
  • 364
  • 4
  • 22
1
vote
0 answers

How convert Data class to JsonElement in kotlinx

I'm trying to convert a kotlin dataclass to a JsonElement, is there a way to do it using kotlin? @Serializable data class SubjectContext( val name: String, var programContext: Properties? = null ) @Serializable data class Properties( …
C.Meza
  • 11
  • 3
1
vote
1 answer

JsonElement GetRawText method throws "Operation is not valid" exception on empty array

Situation I am running into an issue with my implementation of .NET Core's System.Text.Json.JsonSerializer. The API which my application utilizes for getting data returns JSON in the following format: { "context": "SomeUnusedContextValue", …
thebugsdontwork
  • 401
  • 3
  • 17
0
votes
1 answer

How to set the value of a property of a JsonElement Object

I'm having a List of JsonElement, and I want to set the value of each element property through iteration but I don't know how to proceed with a JsonElement object. Here my code : List exportExported = GetDatas(); foreach (JsonElement…
harili
  • 406
  • 9
  • 24
0
votes
2 answers

Model to JsonElement

What is the best/quickest way to convert a Model to JsonElement? Background: I have existing code for a Controller that passes JsonElement from the request body to a repository. Now I have another Controller that first needs to do some logic on the…
Xaphann
  • 3,195
  • 10
  • 42
  • 70
0
votes
1 answer

Parse native json values from array stored jsonb column in postgres with Entity Framework .NET Core NpgSql

My team has a table in postgres, let's call it Thing. It looks like this: Thing Table: id value type integer jsonb string Here are some sample records id value type 1 "hello" string 2 123 number 3 { "name": "foo"…
ahanusa
  • 969
  • 1
  • 9
  • 11
0
votes
1 answer

JSON Type not supported for int datatype --> JSON type not supported. (Parameter 'ValueKind')\r\nActual value was Number

I have a class Person that has an Age property which is an int. It is persisted down to Cosmos Graph DB. I use the GremlinClient to fetch the record and then I have a Materialize method to rebuild . If the Person class doesn't have any int types…
Robert Green MBA
  • 1,834
  • 1
  • 22
  • 45
0
votes
2 answers

list of strings can not be converted to gson.JsonElement

I have want to create a jsonObject in java of this type: "a": "b", "c": { "d": { "e": [ "f", "g", "h" ] } } Following is a snippet of the code where I try to add the value of "e" given in the form of the list: import…
0
votes
2 answers

How to create a domain object from a Json element?

the external web service returns me a Json file of the…
-1
votes
0 answers

java.lang.ClassCastException: com.google.gson.JsonNull cannot be cast to com.google.gson.JsonObject

I am trying to add the list of customers in JSONObject as given below: for (int j = 0; j < list.size(); j++) { if (list.size() > 0) { JSONObject customerList = new JSONObject(); list.get(j).getId(); customerList.put("id",…
Rahulv
  • 1
  • 2
-2
votes
2 answers

Error on JsonElement cannot be convert to JsonObject

so there is a jsonReqObj, jsonReqObj = { "postData" : { "name":"abc", "age": 3, "details": { "eyeColor":"green", "height": "172cm", "weight": "124lb", } } } And there is a save function that will return a…
AshH
  • 39
  • 7