I'm trying to investigate different approaches to an idea I have brewing in my head and I'm not really sure how to search for what I'm trying to do.
I have a series of functions. These all transform the same JSON format (schema) (with differing data). Into different objects (different schemas).
For example I might have JSON like...
{
heading: "Fogmeister",
type: "person",
body_text: "iOS developer",
sections: [
{
heading: 'Describing a transform between two sets of data... a "meta-transform"?',
type: "post",
body_text: "I'm trying to investigate..."
},
{
// other post
}
]
}
And I would want to transform it to a user object like...
{
name: "Fogmeister",
profile: "iOS developer",
posts: [
{ title: 'Describing a transform between two sets of data... a "meta-transform"?' },
{ title: 'Other title' }
]
}
But I might have some different JSON like...
{
heading: 'Describing a transform between two sets of data... a "meta-transform"?',
type: "post",
body_text: "I'm trying to investigate...",
sections: [
{
heading: null,
type: "answer",
body_text: "What you're looking for is..."
},
{
// other answer
}
]
}
And I would want to transform it to a post object like...
{
title: 'Describing a transform between two sets of data... a "meta-transform"?',
body: "I'm trying to investigate...",
answers: [
{ body_text: "What you're looking for is..." },
{ body_text: 'Other answer' }
]
}
Hopefully from this small example you can see that the input schema is the same but the output schema might be very different.
I currently have different functions for mapping each different type. But I'm trying to see if I can come up with a way where I can describe
the mapping between the input and output and then put that into an object (or something).
That way I can have a single function that uses this Mapping
object to transform the data.
But... I don't know if this is something that has a name already. It's sort of a meta-transform
as I want to be able to describe the transform rather than doing the transform myself.
Is there something I can google that will provide more information about this sort of programming?
I'm not looking for code that will do this. More just material I can read around the subject so I can do it myself.
Thanks