Skip to Content

Create JSON with date in Unix Time format

I need to create a JSON document for a REST web service call. In this JSON there is a date field that needs to formatted in Unix Time (seconds since 1st of January 1970)

Request: [
} ]

The data is coming from an ABAP Structure:

Is there a way to create such a JSON directly via e.g. CALL TRANSFORMATION or is there at least a method/function module to convert ABAP dates to UNIX Time?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 02, 2017 at 04:47 PM

    You may create an ST transformation with <tt:value ... option="fmt(ticks)"/> (cf ST - option, Mapping Rules) which will generate "Date":/Date(1418342400000)/

    If you don't want this format, then you need to use an additional ABAP field that you calculate yourself or call a method from within ST (CONVERT DATE ... INTO TIME STAMP ...)

    You may generate automatically JSON from ABAP, using writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ), and CALL TRANSFORMATION ... RESULT XML writer (cf SCN blog post ABAP and JSON, by Horst Keller, on 2013/01/07)

    Add comment
    10|10000 characters needed characters exceeded