I'm looking for a tool/standard that converts allows configurable translation of json from one format, to another.
For example, lets say I have a source json:
{
"user": {
"firstName": "bob",
"lastName" : "jones"
}
}
And I wanted to be create creating json objects like:
{
fName: "bob",
lName: "jones"
}
Then I might have a translation configuration like:
{
mappings: [
{
from: "src.user.firstName",
to: "target.fName"
},
{
from: "src.user.lastName",
to: "target.lName"
}
]
}
What I'm really looking for is a standard that does this in multiple languages, but failing that, if you can suggest tools for Go and JavaScript.
Note also, that you might want to do things like:
- Extract values from arrays
Maybe like:
{
mappings: [
{
from: "src.user.favoriteColors[0]",
to: "target.userFirstFavouriteColor",
}
}
}
- Put values into arrays
eg. translating:
{
userMap: {
id1: {
name: "bob"
},
id2: {
name: "alice"
}
}
}
to:
users: [
{
name: "bob"
},
{
name: "alice"
}
]
}
With a configuration maybe like:
{
mappings: [
{
from: "src.userMap.*",
to: "target.users[]",
}
}
}
- Combine multiple values into one
eg. Maybe like:
{
mappings: [
{
from: ["src.user.fName", "src.user.lName"],
to: "target.fullName",
stringFn: "{0} {1}"
}
}
}
I'm basically thinking XSLT but for json.
Does such a standard exist?