Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Parsing data between JSON schemas #623

Open
dluiscosta opened this issue Apr 20, 2021 · 1 comment
Open

Question: Parsing data between JSON schemas #623

dluiscosta opened this issue Apr 20, 2021 · 1 comment
Labels

Comments

@dluiscosta
Copy link

Is there's a direct way with schematics to not only define models related to a JSON schema, but also specify how to populate it with data from another JSON schema?

For example, suppose I have a system with an internal schematics model specification, but I need to fetch data from a third-party service (or several) which gives me the data I need, but in a JSON satisfying a JSON schema of different structuring:

  • fields might have different names;
  • field values might have different formats;
  • internal fields might need to be inferred from multiple third-party fields;
  • fields, in any level of depth, might be represented in a flattened manner in one side and nested manner on the other;
    Ex: {"weather_temperature": 75, "weather_wind": 100} as opposed to {"weather": {"temperature": 75, "wind": 100}}
  • third-party objects might need to be aggregated or disaggregated in order to fit the semantic of the internal schematics.

In the end, what I'm searching for is a simple, preferably declarative way to specify, for each of the fields present in my internal schematics representation, where is the related information present within a different schema, in a way that I'm able to simply feed the third-party JSON to my outer internal model's constructor.

@lkraider
Copy link
Contributor

That's a complex requirement, you will need a mapper between two models for that.
Maybe you could achieve something close by having @serializable setters that implicitly set inner fields mapping from model1 to model2.

In a personal project I created a small DSL to convert between JSON structures, but I didn't require data validation there, although I could see a case where plugging a DSL to ingest data into a validator could make sense. But I feel this would be outside the scope of schematics itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants