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

Creating an array #1235

Open
Linuski opened this issue Feb 29, 2024 · 1 comment
Open

Creating an array #1235

Linuski opened this issue Feb 29, 2024 · 1 comment

Comments

@Linuski
Copy link

Linuski commented Feb 29, 2024

I have this kind of json:
{ "entities": {
"organisations": [
{ "id": "b9c0b61b-e843-48c8-83a2-52bf2ea00971", "label": "ReCAAP ISC" }, ... other things ],
"places": [
{ "id": "97fe568b-5b25-46dc-bb85-0a7f52996f1d", "label": "Bangladesh" }, ... other things ]
}
}

I would like to have this:
[
{ "id": "b9c0b61b-e843-48c8-83a2-52bf2ea00971", "label": "ReCAAP ISC" },
{ "id": "97fe568b-5b25-46dc-bb85-0a7f52996f1d", "label": "Bangladesh" }
]

I used this transformation:
[{
"operation": "shift",
"spec": {
"entities": {
"places": {
"": "R0[#2]"
},
"organisations": {
"
": "R0[#2]"
}
}
}
}, {
"operation": "shift",
"spec": {
"R0": { "*": "" }
}
}
]

which works well for thsi case but when I have this other case:
{ "entities": {
"organisations": [
{ "id": "b9c0b61b-e843-48c8-83a2-52bf2ea00971", "label": "ReCAAP ISC" } ]
}
}
the result is not an array:
{
"id": "b9c0b61b-e843-48c8-83a2-52bf2ea00971", "label": "ReCAAP ISC" }
}
How can I fix this?

@gbouget
Copy link

gbouget commented Feb 29, 2024

Does this specification cover all cases?

[
  {
    "operation": "shift",
    "spec": {
      "entities": {
        "organisations|places": {
          "*": {
            "id|label": "&2.&1.&"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[]"
      }
    }
  }
]

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