Casting dates to and from JSON

Hi,

So when Appian writes dates to Json, it cannot cast those values correctly if it reads them back.

load(
  local!data:{
    today()
  },
  local!jsonData: a!toJson(
    local!data
  ),
  local!fromJson: cast(
    typeof(today()),
    a!fromJson(
      local!jsonData
    )
  ),  
  a!sectionLayout(
    contents: {
      a!textField(
        value: local!jsonData
      ),
      a!textField(
        value: local!fromJson
      )
    }
  )
)

Do I have to manually alter the string in order to reorder the date from "YYYY-MM-DDZ" to "DD-MM-YYYYZ" before I run from Json?

Is there a reason that Appian designed it this way?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    I've just double checked and it looks like it works pretty easily if you cast the date / datetime to string before doing the initial JSON conversion, and the resulting value coming back in from json can be cast back to date / datetime using "todatetime()", though perhaps some of the inherent extra data (seconds, time zone, etc) is lost this way.

    I also am curious what the official recommended methodology is for retrieving the datetime value when the date data type itself is used in the JSON string. It seems like there should be some way to do it automatically without needing to, say, build a manual parser helper rule.
  • Huh interestingly it even accepts the format of mmm/dd/yyyy.
    But if given mm/dd/yyyy it will interpret it incorrectly, except when the day is greater than 12 as it seems to do some logical shuffling when it sees an invalid month.
    Pretty strange and it would be great if we could get some explanation on how Appian expects to be given its Json Data, as I think I would prefer it to fail consistently than behave unexpectedly.

Reply
  • Huh interestingly it even accepts the format of mmm/dd/yyyy.
    But if given mm/dd/yyyy it will interpret it incorrectly, except when the day is greater than 12 as it seems to do some logical shuffling when it sees an invalid month.
    Pretty strange and it would be great if we could get some explanation on how Appian expects to be given its Json Data, as I think I would prefer it to fail consistently than behave unexpectedly.

Children
No Data