Web Connection
How to generate an empty date string or null value in json via wwwc and vfp
Gravatar is a globally recognized avatar based on your email address. How to generate an empty date string or null value in json via wwwc and vfp
  Michael B
  All
  Oct 27, 2021 @ 12:31pm

Hi Rick,

I have a get API that returns credit data for items returned in my WWWC app. If the item does not have a credit yet, the 'refunded' date time field is empty.

When I do this

loSerializer.Serialize("cursor:tReturnLines")

I end up with an empty date attribute like this: "date_credited": "1970-01-01T06:00:00Z"

I was hoping that it would say null or " / / : : AM" -

Any simple suggestions that would be considered standard practice?

Gravatar is a globally recognized avatar based on your email address. re: How to generate an empty date string or null value in json via wwwc and vfp
  Michael B
  Michael B
  Oct 27, 2021 @ 12:37pm

I discovered that if the table definition does not have 'nulls' allowed, I could get it to work by doing this: CAST(IIF(empty(wws_returns.refunddate),.null.,ttod(wws_returns.refunddate)) as date) as date_credited

Thanks 😃

Gravatar is a globally recognized avatar based on your email address. re: How to generate an empty date string or null value in json via wwwc and vfp
  Rick Strahl
  Michael B
  Oct 27, 2021 @ 03:50pm

There's no such thing as an empty date in JSON, so you have to return something. The default JavaScript date is the date that you see, so that's standard behavior in JSON.

As you've found out, you can replace the value in a SELECT to get the value you want. I'm not sure if I would return null for a date because that will likely break some languages that have to consume the value, but you can set the date to some really low value like ? {^ 1700-01-01 } (I guess FoxPro has some sort of minimum date as you can't set 1600).

+++ Rick ---

© 1996-2025