M
M
Maxim Gusev2021-03-26 17:25:58
Angular
Maxim Gusev, 2021-03-26 17:25:58

What is the best way to parse untyped JSON?

Hello, please tell me if there is any good approach for parsing untyped JSON data?

The backend returns the JSON content as an object. The data needs to be received and parsed.

JSON is one and it is large, some of the data is needed by one component, some by others, and this data needs to be received in the component's resolver. However, every time this data is needed, it is necessary to describe the interface for each component.
Is there any solution so as not to write the same type of destructuring functions and each time not to describe the interface that is needed essentially once.

An example of the current implementation on Stackblitz

At the moment, the object is destructured and a new object is formed in accordance with the interface.
The problem is that for each router the data set is different and you have to write your own method individually for each component.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-04-20
@Aetae

The question is not very clear, but if the problem is json typing, then Google is full of json to ts generators that will generate the necessary interfaces for you. There are also libraries that will allow you to automate this issue and runtime helpers . And, finally, if the server provides its spec in open api (swagger), there are generators that will immediately generate all the necessary body kit for you, incl. for angular.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question