json-mapper-json
json-mapper-json copied to clipboard
[Question]: Array from single item
Hey,
Is there a way to output an array of one item from a single object?
Input Object:
{ email: "[email protected]" }
Required output:
{ emails: [ { email: "[email protected]" }] }
I have tried the below but its not quite what I need.
{
"emails": {
"path": "$empty",
"nested": {
"email": {
"path": "email"
}
}
}
}
Also this is invalid:
{
"emails": [{
"path": "$empty",
"nested": {
"email": {
"path": "email"
}
}
}]
}
This is an old question, but in case any else hits the same problem I had to do something similar and used a 'formatting' function to handle it:
"emails": {
path: "email",
formatting: (email) => {
return [{ email }]
}
}
"emails": { path: "email", formatting: (email) => { return [{ email }] } } This will cause an issue if there is a nested element for emails.
@preethamkumarg what error do you get?
Could you give me more context please