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

Is there a function to insert current datetime? #531

Closed
jag959 opened this issue Mar 6, 2018 · 7 comments
Closed

Is there a function to insert current datetime? #531

jag959 opened this issue Mar 6, 2018 · 7 comments

Comments

@jag959
Copy link

jag959 commented Mar 6, 2018

Need assistance on trying to insert the current date/time using Jolt.

I tried (as shown below) using "${now()}"; but the output is not producing the date/time.

JSON input:

[
  {
    "ProdId": "Filler",
    "ProductName": "Z Dry Filler",
    "Trait": "",
    "Variety": "",
    "SuggestedRetailPrice": "0.0000",
    "CropId": "",
    "DeptId": "067001"
  },
  {
    "ProdId": "Clay",
    "ProductName": "Z Clay",
    "Trait": "",
    "Variety": "",
    "SuggestedRetailPrice": "0.0000",
    "CropId": "",
    "DeptId": "067001"
  }
]

Jolt Spec:

[
  {
    "operation": "default",
    "spec": {
      "*": {
        "LastUpdated": "${now()}"
      }
    }
}
]

Output:

[ {
  "ProdId" : "Filler",
  "ProductName" : "Z Dry Filler",
  "Trait" : "",
  "Variety" : "",
  "SuggestedRetailPrice" : "0.0000",
  "CropId" : "",
  "DeptId" : "067001",
  "LastUpdated" : "${now()}"
}, {
  "ProdId" : "Clay",
  "ProductName" : "Z Clay",
  "Trait" : "",
  "Variety" : "",
  "SuggestedRetailPrice" : "0.0000",
  "CropId" : "",
  "DeptId" : "067001",
  "LastUpdated" : "${now()}"
} ]

Desired Output:

[ {
  "ProdId" : "Filler",
  "ProductName" : "Z Dry Filler",
  "Trait" : "",
  "Variety" : "",
  "SuggestedRetailPrice" : "0.0000",
  "CropId" : "",
  "DeptId" : "067001",
  "LastUpdated" : "2018-03-06T15:38:19Z"
}, {
  "ProdId" : "Clay",
  "ProductName" : "Z Clay",
  "Trait" : "",
  "Variety" : "",
  "SuggestedRetailPrice" : "0.0000",
  "CropId" : "",
  "DeptId" : "067001",
  "LastUpdated" : "2018-03-06T15:38:19Z"
} ]

I'm not sure Jolt can even accept such variables.

Thanks in advance for any assistance.

@milosimpson
Copy link
Contributor

@milosimpson
Copy link
Contributor

There is no way to ask jolt for "now". Gets into a messy world of date formatting.

I recommend "ninjaing" the data to the json first, and then using Jolt to push that data to all the places you want it to go.

@milosimpson
Copy link
Contributor

milosimpson commented Mar 6, 2018

For example, if you could fix your input "before jolt" to be

Input

{
  "ninjaed-in-time": "2018-03-06T15:38:19Z",
  "list": [
    {
      "ProdId": "Filler",
      "ProductName": "Z Dry Filler",
      "Trait": "",
      "Variety": "",
      "SuggestedRetailPrice": "0.0000",
      "CropId": "",
      "DeptId": "067001"
    },
    {
      "ProdId": "Clay",
      "ProductName": "Z Clay",
      "Trait": "",
      "Variety": "",
      "SuggestedRetailPrice": "0.0000",
      "CropId": "",
      "DeptId": "067001"
    }
  ]
}

Spec

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "list": {
        "*": {
          "LastUpdated": "@(3,ninjaed-in-time)"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "list": ""
    }
  }
]

Would generate the output you want.

@jag959
Copy link
Author

jag959 commented Mar 6, 2018

Thank you.

@Joseph2424
Copy link

What does "ninjaed" stand for?

@milosimpson
Copy link
Contributor

In this context it means "sneak". Before Jolt, "sneak"/"ninja" in an extra field, and then use Jolt to pull/use that field.

@Joseph2424
Copy link

How can you accomplish this in Java? Any suggestions?

@jsurls jsurls closed this as completed Jun 6, 2019
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

4 participants