#JSON from DB to TS object
27 messages · Page 1 of 1 (latest)
Im requesting big object\
this is just a part of it
if i wouldnt, i would just map it somehow
The advantage of using js/ts is that each object has the same structure as json. Therefore create an interface with the property REG_TITLE_COMMENT like this
export interface MyData {
REG_TITLE_COMMENT: string
OtherProperty: string
...
}
If youre using the http client stick to the doc that jbnizet sent
So what? What does it change if the object is big or not? The solution is always the same: define an interface describing your object structure, and use it.
Do you actually care about just one of its properties?
No it can be changed manually
added or removed
Threre can be multiple options and I need to take all, put them into some object and use them as needed
String of JSON is stored in
Object.nastavenia.textyJsonSk - this object I need to parse somehow
.\"}",
"textyJsonEn": "{\"REG_TITLE_COMMENT\":\"Due to full capacity, accommodation is no longer possible. In case of interest, the participant can provide their own accommodation and meals, for example in a nearby guest house located 500 meters from the conference venue (the conference fee is reduced). Please contact us if you will require the help with accommodation near the conference venue \"}"
},
I don't know how this object with REG_TITLE_COMMENT relates with the big one you showed earlier.
im having big object about settings
and there inside it is another object i need
and there is that one I showed you before your message
interface Something {
navastenia: {
textyJsonSk: string;
}
}
interface JsonThing {
REG_TITLE_COMMENT: string;
}
const result$: Observable<JsonThing> = http.get<Something>(url).pipe(
map(something => JSON.parse(something.navastenia.textyJsonSk))
);
That's why I asked if you care about just that property or not.
So you need to define interfaces for all the possible properties of that object, and in turn for all the object nested inside it, or inside its arrays.
yes and than map it as jbiznet showed?
If you define all the interfaces you don't need to parse by JSON
Well, if you care about other properties, you probably won't map, no. But you will still get a Something, then access the property you asked about and use JSON.parse() to parse it as a JsonThing.
Yes, he does, because he has an JSON string stored inside a property of the main JSON.