#JSON from DB to TS object

27 messages · Page 1 of 1 (latest)

fast star
#

this is just a part of it

#

if i wouldnt, i would just map it somehow

fierce sage
#

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
    ...
}
fast star
#

This is full object 😄

fierce sage
#

If youre using the http client stick to the doc that jbnizet sent

sleek sand
acoustic garden
#

Do you actually care about just one of its properties?

fast star
#

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 \"}"
    },
acoustic garden
#

I don't know how this object with REG_TITLE_COMMENT relates with the big one you showed earlier.

fast star
#

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

sleek sand
#
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))
);
acoustic garden
#

That's why I asked if you care about just that property or not.

acoustic garden
#

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.

fast star
acoustic garden
#

If you define all the interfaces you don't need to parse by JSON

sleek sand
sleek sand