1

I need help, I'm new to Jolt. There is a json file:

{
  "Date": "2021-01-01",
  "Status": "New",
  "Agreements": [
    {
      "ID_agreement": "12345",
      "ID": "fffffff",
      "balance": {
        "rub": 5,
        "usd": 6,
        "eur": 7
      },
      "withdrawal": {
        "rub": 8,
        "usd": 45,
        "eur": 6
      }
    },
    {
      "ID_agreement": "6789",
      "ID": "dddddd",
      "balance": {
        "rub": 10,
        "usd": 20,
        "eur": 30
      }
    }
  ]
}

At the output, you really need to get something like this:

{
  "type": "DATA",
  "date": "2021-01-01",
  "id_agreement": "12345",
  "id": "fffffff",
  "source": "SITE",
  "unloadDateTime": "current date if possible",
  "balance": {
    "rub": 5,
    "usd": 6,
    "eur": 7
  },
  "withdrawal": {
    "rub": 8,
    "usd": 45,
    "eur": 6
  }
},
{
  "type": "DATA",
  "date": "2021-01-01",
  "id_agreement": "6789",
  "id": "dddddd",
  "source": "SITE",
  "unloadDateTime": "current date if possible",
  "balance": {
    "rub": 10,
    "usd": 20,
    "eur": 30
}

must be added to each block:

  "type": "DATA",
  "date": "2021-01-01",
  "source": "SITE",
  "unloadDateTime": "current date if possible"

and delete

"Status": "New"

The original file is large, and the fields withdrawal/balance are somewhere there, somewhere not

my initial Jolt spec:

[
  {
    "operation": "remove",
    "spec": {
      "Status": ""
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Agreements": {
        "*": "&"
      },
      "balance": {
        "*": "&"
      }
    }
  }
 ]

Hours of disassembly with the formatter did not lead to anything, the task is one-time, please help, dear colleagues!

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55

1 Answers1

0

First of all, the object balance located at the bottom part is redundant. After removing that, apply # notation to provide those fixed values you want updating the current shift transformation such as

[
  {
    "operation": "remove",
    "spec": {
      "Status": ""
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Agreements": {
        "*": {
          "#DATA": "[&1].type",
          "#2021-01-01": "[&1].date",
          "#SITE": "[&1].source",
          "#current date if possible": "[&1].unloadDateTime",
          "*": {
            "@": "[&2].&1"
          }
        }
      }
    }
  }
 ]

enter image description here

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55