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

unable to create nested array #15

Closed
horijon opened this issue Apr 29, 2022 · 3 comments
Closed

unable to create nested array #15

horijon opened this issue Apr 29, 2022 · 3 comments

Comments

@horijon
Copy link

horijon commented Apr 29, 2022

Want to convert/unflatten from

const jsonData = {
    "description": "SARS-CoV-2 (COVID-19) IgM Ab [Units/volume] in Serum or Plasma by Immunoassay"
};

to result

{
   "category":[
      {
         "coding":[
            {
               "display":"SARS-CoV-2 (COVID-19) IgM Ab [Units/volume] in Serum or Plasma by Immunoassay"
            }
         ]
      }
   ]
}

How do i write mapping logic for such case?
@ahmadassaf I am eagerly seeking for your kind help! And thank you for the library!

@ahmadassaf
Copy link
Member

ahmadassaf commented May 4, 2022

Hi @horijon,

to achieve the above you can define your mappings as:

{
  category: {
    "output": [],
    "innerDocument": "!",
    "mappings": {
      coding: {
        "output": [],
        "innerDocument": "!",
        "mappings": {
            "value": "description"
        }
      }
    }
  }
}

I created a sample repl.it example for you here and you can see that the output will be:

{
  "category": [
    {
      "coding": [
        {
          "value": "SARS-CoV-2 (COVID-19) IgM Ab [Units/volume] in Serum or Plasma by Immunoassay"
        }
      ]
    }
  ]
}

@horijon
Copy link
Author

horijon commented May 4, 2022

Thanks a lot! @ahmadassaf
I also want to revert it back (flatten). Please guide me for this as well.

@ahmadassaf
Copy link
Member

if you will always have the same exact structure, so only one item in the array it is as simple as a JSON path traversal.

{
  description: "category[0].coding[0].value"
}

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

No branches or pull requests

2 participants