Skip to main content

Example of Creating an EDIFACT message from JSON

EDIFACT

Ossi Galkin avatar
Written by Ossi Galkin
Updated over a year ago

Creating an EDIFACT message from JSON

With the Frends Edifact Tasks, it is very straightforward to create a new EDIFACT message either from formatted JSON or XML data.

The Edifact CreateFromJson Task expects the JSON data to be provided in the very same JSON structure that the Edifact ConvertToJson Task returns as converted EDIFACT messages.


Step 1: Create an example of the JSON source message.

The best way to create the JSON data for the Edifact CreateFromJson Task is to first convert an example EDIFACT message to a JSON format and use these JSON formatted messages as a template for the required JSON structure. I recommend using example messages which are as close to real-life EDIFACT messages as possible to make it easier to find all the needed fields.

Step 2: Create dynamic mapping by using the example JSON source message as a mapping template

The JSON source message is created dynamically using the very same techniques seen in the module "Mapping from an EDIFACT JToken tree", except the source data can have a different format and structure and the resulting data follows the JSON structure of the example JSON source message created in Step 1.


Step 3: The JSON source message is given as a parameter for the Edifact CreateFromJson Task.

Now that you have created the JSON source message in Step 2, it needs to be passed to the Edifact CreateFromJson Task as a parameter.

In the example below, the JSON source message is given as a Manual Trigger Parameter. In a real-world Frends Process, instead of referencing the Trigger Parameter, you need to refer to the Frends Variable containing the JSON source message.

In the picture below, you can see an example of a very simple Process where the JSON data for the Edifact ConvertFromJson Task is given as a Manual Trigger parameter:


Step 4: Store or use the result of the Edifact CreateFromJson Task.

The Edifact CreateFromJson Task will validate the input JSON message structure and report any errors if the message is not valid.

When there are no errors, you can for example store the EDIFACT message content to a file and send it to an SFTP server with another Frends Task.

Note that the resulting EDIFACT message does not have any line feeds because this is the default EDIFACT formatting style. Back in the years when EDIFACT was developed, it was more important to keep the message size as small as possible rather than creating messages that are easy to read for humans.


You can apply this same creative process to any standard EDIFACT message type.

The next article is an Example of Frends and SAP.

Did this answer your question?