json-mapper-json icon indicating copy to clipboard operation
json-mapper-json copied to clipboard

[Question]: Array from single item

Open Dekeyras opened this issue 5 years ago • 3 comments

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"
      }
    }
  }]
}

Dekeyras avatar Feb 07 '20 15:02 Dekeyras

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 }]
    }
}

joncarlson avatar Apr 06 '20 16:04 joncarlson

"emails": { path: "email", formatting: (email) => { return [{ email }] } } This will cause an issue if there is a nested element for emails.

preethamkumarg avatar Aug 17 '21 07:08 preethamkumarg

@preethamkumarg what error do you get?

Could you give me more context please

marchah avatar Aug 17 '21 23:08 marchah