bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.54k stars 328 forks source link

convert object to Array #1188

Open amorKGitHub opened 1 year ago

amorKGitHub commented 1 year ago

Hello I'm a newbie at this , an anyone help

I have this json "interventions" : [ { "donneesGenerales" : { "etat" : { "@code" : "DMND", "libelle" : "En cours" }, "dateLimite" : "2023-03-09", "application" : { "@code" : "QETGC" }, "refSi" : "84975" }, "operations" : { "operation" : { "@code" : "P", "libelle" : "Pose&MES" } }, "demande" : { "dateSouhaitee" : "2023-03-02", "heureDebut" : "12:00:00" }, "planification" : { "datePrevue" : "2023-03-02", "heureDebutPrevue" : "12:00:00" } } ] I need to convert the object operations to Array

here my spec :

"interventions": { "": { "@": "consulterAffaireResponse.interventions[#2]", "operations": { "": { "@": "consulterAffaireResponse.interventions[#1].operations" } } } }

Any suggestions would be greatly appreciated. Thanks in advance

ydv-prakhar commented 1 year ago

Hi @amorKGitHub, Since you mentioned that you need to convert the object operations to an array I am assuming you want the following output

{
  "donneesGenerales" : {
    "etat" : {
      "@code" : "DMND",
      "libelle" : "En cours"
    },
    "dateLimite" : "2023-03-09",
    "application" : {
      "@code" : "QETGC"
    },
    "refSi" : "84975"
  },
  "operations" : [ [ "P", "Pose&MES" ] ],
  "demande" : {
    "dateSouhaitee" : "2023-03-02",
    "heureDebut" : "12:00:00"
  }
}

You can use the following spec to get the desired output

[
  {
    "operation": "shift",
    "spec": {
      "interventions": {
        "*": {
          "donneesGenerales": "&",
          "operations": {
            "operation": {
              "*": "operations.[#2]"
            }
          },
          "demande": "&",
          "plantification": "&"
        }
      }
    }
    }
  ]

Hope this helps.