Dart Json nested object parsing failure - json

I've got json file with some nested objects inside subs in it:
{
"version": 1,
"data": [{
"married": true,
"subs":[
{
"name":{
"sub1":{}
**},**
},
]
},
]}
If I add another 'name' object (with comma as separator), jsonDecode returns nothing.
if there goes single object, without comma - it's ok.
My Json structure is correct, and it's not restricted to use nested objects at all. Please anyone help.

This line has problem **},** and if changed to }, the problem will be solved..
you can check your json by online tools (e.g https://jsonformatter.curiousconcept.com/#)

Related

How do I ignore empty JSON arrays when deserializing POCO classes?

I am using the NuGet package Hl7.Fhir.STU3 to save me from having to create all the POCO classes.
The Json returned from the NHS FHIR Server is (I've removed a huge chunk to make it easier to read):
{
"id": "000049660991",
"meta": {
"versionId": "3",
"profile": [
"https://fhir.nhs.uk/STU3/StructureDefinition/eRS-ReferralRequest-1"
]
},
"resourceType": "ReferralRequest",
"supportingInfo": [],
"intent": "plan"
}
The problem comes when I try to deserialize it as the "supportingInfo" element contains an empty array so I receive the following error (ignore the position):
Hl7.Fhir.Serialization.DeserializationFailedException: 'One or more errors occurred. (An array needs to have at least one element. At line 1, position 2445.)'
Is there a way to ignore empty arrays?

Having a problem with iterating over multiple json objects and showing them in div with vue.js

Trying to create a website that takes in information from an API, however I don't really understand how to do it seeing that I need all results grouped up and the API I've created almost never gives a response with the same amounts of objects. So the question is, seeing that I use vue.js and axios is there any way to loop through the json objects to show each of the objects in a seperate ? I manage to do it when there are a specified amounts, but I want to make it dynamic so I don't hardcode into the variables what part of the response I need to set to each variable.
UPDATE: I've tried to use v-for, but seeing that I need to have the output quite structured it doesn't really help, I've also tried Nested V-for loops, once again I can't get the accuracy that I'm looking for.
UPDATE2: Also should be added, when I say JSON object I actually ment js object. the json.parse() has been used on the json.
UPDATE3: Updated the JSON to actual data that I'm using for the application.
Every div need a lemma, a paradigm tagset, inflection tagset and inflectionForms and a table for all the meanings. Just need meaning not meaningText. TranslationId is not important. The JTranslate that wraps every object will be removed, just kinda tired of the Java at the moment, will do that later today and do the adjustments on the vue projects aswell regarding that deletion.
Actually your json format is invalid
{
"object1":{
"name": "test",
"data": "test"
},
"object2":{
"name": "test2",
"data": "test2"
},
"object3":{
"name": "test2",
"data": "test2"
}
}
it should be like above and use JSON.parse() method to simply convert the json to javascript object
Valid Object:
var objects = {
"object1":{
"name": "test",
"data": "test"
},
"object2":{
"name": "test2",
"data": "test2"
},
"object3":{
"name": "test2",
"data": "test2"
}
}
for iteration use
<div v-for="(object,index) in objects" :key="index">
{{object}}
</div>
The correct object as an array:
test: [
{
object1: {
name: 'name1',
data: 'content1'
}
},
{
object2: {
name: 'name1',
data: 'content1'
}
},
{
object3: {
name: 'name3',
data: 'content3'
}
}
]
can be mapped as a computed property inside the script tages:
computed: {
mappedTest() {
return this.test.map(entry => {
const key = Object.keys(entry)[0];
return { name: entry[key].name, data: entry[key].data };
});
}
},
and call it inside the template
<div
v-for="testObject in mappedTest"
:key="testObject"
>
name: {{testObject.name}}; data: {{testObject.data}}
</div>
I was very tired when I asked this question, apparently I did everything wrong. Can easily be solved by nested v-for loops.

converting one JSON structure into another JSON structure

The client side expects JSON string in the below format
descriptions": [
{
"lang": "string",
"size": "string",
"text": "string",
"type": "string"
}
],
, but the received JSON is a bit different - like below
"descriptions":{
"desc":[
{
"size":string,
"lang":"string",
"type":"string",
"content":"string"
}
]
},
Is there anyway to ignore the "desc" part - for eg. using a JSON annotation ? Context: I am passing this JSON through a REST API call and it will be automatically converted to a Java object at the receiving end.
A simple
descriptions = descriptions.desc;
will do.
You just construct the object you need:
var clientDescriptions = descriptions.desc.map(function(d) {
size: d.size,
type: d.type,
lang: d.lang,
content: d.text
});
If you are using Gson, it is possible to use custom JsonDeserializer / JsonSerializer for your Java model. Your model object and API can then be cleanly implemented without having to deal with the different json structures.
In my personal experience, the backend has a bug and must be solved, it mustn't be sending malformed data.In the long run it is the best solution.

Suppress datamember attribute name JSON

I have an issue serializing to JSON moving from an IList<"string"> to an IList<"customobject">. The endpoint is expecting an array of strings such as :-
"options": [
"foo1",
"foo2"
]
With the customobject I am getting the following :-
"options": [
{
"name": "foo1"
},
{
"name": "foo2"
}
]
Is there any way to suppress name attribute and continue to get an array of strings with WCF, or do I have to do it another way? Any help would be much appreciated.
Would still appreciate any insight into the possibility of doing this, but for now has been resolved by adding the option as a string as well as an object, and only exporting the string. I know this is duplication, but will have to wait for an update to the endpoint.

How to read nested json file with several roots in extjs

How to read the following json file and display in extjs grid columns?
{
"users": [
{
"id": 123,
"name": "Ed",
"orders": [
{
"id": 50,
"total": 100,
}
]
}
]
}
Could someone explain how to read the nested data in the json? I have tried a lot of options like renderer functions, using the '.' property, etc.
Edit: I would like to read the data within "orders", which are "id" and "total".
You are trying to read in an array nested in an object nested in an array.
So your root would have to be users[0].orders
Is that really what you are trying to do?
Working code:
http://jsfiddle.net/el_chief/s6Ynp/1/
Why is your code nested like this?