Products Downloads


French version


 


ADELIA

VADELIA

SADELIA

WADELIA


(I/B)

(I/B) (C/S)

(B) (S)

(I/B) (C/S)




Section for use

All


Syntax

CONV_DATA dataToConvert origFormat convertedData destFormat


dataToConvert

<alpha variable> | <image variable> | <image class> | *SOURCE_FILE(FileName)

FileName

<alpha variable> | <alpha constant>

origFormat

<alpha variable | alpha constant> | none

convertedData

<alpha variable> | <image variable> | <image class> | *DEST_FILE(FileName)

FileName

<alpha variable> | <alpha constant>

destFormat

<alpha variable | alpha constant> | none


Description

The CONV_DATA instruction is used to convert the format of data contained in the dataToConvert parameter.


The origFormat parameter defines the original format of the data. It is mandatory when the original data is not a class-type variable, otherwise it must not be specified.


The destFormat parameter defines the format into which the data must be converted. It is mandatory when the destination data is not a class-type variable, otherwise it must not be indicated.


The convertedData parameter receives the converted data in return.


The dataToConvert parameter contains the data to convert.

When *SOURCE_FILE is indicated, dataToConvert must contain the name of the file to convert.

Otherwise, it contains the data to convert, either in an alpha variable or in an image variable.


The origFormat parameter defines the original format of the data.

The possible values are:

  • 'JSON'   => JSON format

  • 'JSON(JsonOptionsSeries)'
    JsonOptionsSeries => Jsonoption | Jsonoption, JsonOptionsSeries

Jsonoption => *WITH_ROOT | *DIGIT_NAME

The keyword *WITH_ROOT is valid only when you wish to deserialize the data Json in class.
If indicated, the conversion expects to have the root attribute in the Json data.

Otherwise an exception is thrown.
The *DIGIT_NAME keyword forces the addition of a _DIGIT_ prefix in front of tag names starting with a number (to avoid having an invalid file in XML).

  • 'XML'   => XML format

  • 'XML(XmlOptionsSeries)'
    XmlOptionsSeries => XmlOption  | XmlOption, XmlOptionsSeries

XmlOption =>

<TagPathsSeries> |

*ARRAY=<TagPathsSeries> |

*IGNORE_EMPTY_ARRAY | 

*ALPHA=<TagPathsSeries>


tagPathsSeries: when preceded by the keyword *ARRAY or not preceded by a keyword, indicates the tree views (separated by a comma) of the tags we want to serialize in a JSON array. When preceded by the keyword *ALPHA, it indicates the tree views of the tags we want to systematically convert into an alphanumeric value (even if the value corresponds to a numeric value).


By default, we try to convert each value into a numeric value first then into a decimal and Boolean value. If no conversion is possible, the value type is alphanumeric.


Each tree view must start with the "/" character.


The *ARRAY option only applies for tags containing a single element. Tags containing several elements are naturally converted into a JSON array.

(for example: "XML(/PEOPLE/People)").


The *IGNORE_EMPTY_ARRAY option must be used with *ARRAY and can be used to obtain empty JSON arrays:
"node":[]
Without this option, an empty XML tag converted with the *ARRAY option generates the JSON node "node":[""]


The dataToConvert parameter receives the data in its new format in return.

When *DEST_FILE is indicated, the data is stored in a file. Otherwise, it is stored in an alpha- or image-type variable.


The destFormat parameter defines the conversion format.

The possible values are:

    • 'JSON' => JSON format

    • JSON(JsonOptionsSeries)'
      JsonOptionsSeries => Jsonoption | Jsonoption, JsonOptionsSeries
      Jsonoption =>
      < nodeNameSeq > | *DIGIT_NAME | *WITH_ROOT

      nodeNameSeq: Format where the node names are specified (separated by comma). These names correspond to a JSON collection of elements which the user wants to make anonymous in JSON.
      To specify the root node, it is possible to use the *ROOT special value (for example: 'JSON(*ROOT , People)' )
      The *DIGIT_NAME keyword removes the possible _DIGIT_ prefix in front of XML tag names to define the name of the JSON node (where the actual name of the JSON node must start with a number which is invalid in XML).
      *WITH_ROOT: When the original data is a class, this keyword indicates that the root attribute shall be taken into account during the serialization.


    • 'XML'    => XML format


NB: when the user wants to convert data into XML format and the converted data is contained in a file, encoding is forced to UTF-8.

When the data to convert is contained in an alphanumeric variable, it must be in the current platform's code page.  

When the converted data is contained in an alphanumeric variable, it is encoded in the current platform's code page.

In the case of a conversion from JSON to XML, if there is no root node in the JSON document, then there will be a root node named "Root" in the XML document

Reserved word *RETURN_CODE can be tested after executing the instruction.

If the operation has been carried out successfully, *RETURN_CODE returns *NORMAL.


The table below shows the various possible results:

-1: Invalid parameters.

-2: Error when reading the file containing the data to convert.

-3: Error when writing the file containing the converted data.

-4: Error when reading the image field containing the data to convert.

-5: The specified conversion formats are not correct.

-6: Error during class serialization into JSON data.

-7: Error during deserialization of JSON data.

1: Internal error.

2: Error during the XML data analysis.

3: Error during the JSON data analysis.

4: Error when converting UTF8 characters into EBCDIC or UCS2 (AS400).

5: The name of an element of the input JSON data is invalid.


Example 1

CONV_DATA *SOURCE_FILE('c:\doc\people.xml') 'XML'  *DEST_FILE('c:\doc\people.json') 'JSON'


Example 2

Alpha(250) ORIG_DATA

IMAGE DEST_DATA


ORIG_DATA = '{"PEOPLE":{"People":[{"Surname":"RONDO","FirstName":"Paul","DOB":"1980-10-30"},{"Surname":"DOLA","FirstName":"Laura","DOB":"1990-11-01"}]}}'


CONV_DATA ORIG_DATA DEST_DATA 'XML'


Returns DEST_DATA with the value <?xml version="1.0" encoding="UTF-8" standalone="yes"?><PEOPLE> <People><Name>RONDO</Name><FirstName>Paul</FirstName><>1980-10-30</DOB></People> <People><Name>DOLA</Name><FirstName>Laura</FirstName><DOB>1990-11-01</DOB></People></PEOPLE>


Example 3

ORIG_DATA =' <?xml version="1.0" encoding="UTF-8" ?><PEOPLE> <People><Name>RONDO</Name><FirstName>Paul</FirstName><DOB>1980-10-30</DOB> </People> <People><Name>DOLA</Name><FirstName>Laura</FirstName><DOB>1990-11-01</DOB></People></PEOPLE>


CONV_DATA ORIG_DATA 'XML'  DEST_DATA 'JSON'


Returns DEST_DATA with the value '{"PEOPLE":{"People":[{"Name":"RONDO","FirstName":"Paul","DOB":"1980-10-30"},{"Name":"DOLA","FirstName":"Laura","DOB":"1990-11-01"}]}}'


Example 4

ORIG_DATA =' <?xml version="1.0" encoding="UTF-8" ?><PEOPLE> <People><Name>RONDO</Name><FirstName>Paul</FirstName><DOB>1980-10-30</DOB> </People> <People><Name>DOLA</Name><FirstName>Laura</FirstName><DOB>1990-11-01</DOB></People></PEOPLE>


CONV_DATA ORIG_DATA 'XML'  DEST_DATA 'JSON(*ROOT, People)'


Returns DEST_DATA with the value '[{"Name":"RONDO","FirstName":"Paul","DOB":"1980-10-30"}, {"Name":"DOLA","FirstName":"Laura","DOB":"1990-11-01"}]


Example 5

ORIG_DATA =' <?xml version="1.0" encoding="UTF-8" ?><PEOPLE> <People><Name>RONDO</Name><FirstName>Paul</FirstName><DOB>1980-10-30</DOB> </People></PEOPLE>

 

CONV_DATA ORIG_DATA 'XML (*ARRAY=/PEOPLE/People) '  DEST_DATA 'JSON'


Returns DEST_DATA with the value ' {"PEOPLE":{"People":[{"Name":"RONDO","FirstName":"Paul","DOB":"1980-10-30"}]}}'

Example 6

ORIG_DATA ='<?xml version="1.0" encoding="UTF-8" ?><PEOPLE> <People></Personnes></PEOPLE>' 


CONV_DATA ORIG_DATA 'XML (*IGNORE_EMPTY_ARRAY, *ARRAY=/PEOPLE/People'  DEST_DATA 'JSON' 


Returns DEST_DATA with the value ' {"PEOPLE":{"People":[]}} '


Example 7

ORIG_DATA ='<?xml version="1.0" encoding="UTF-8" ?><EMPLOYEES> <Employees><ID no.>52413</ID no.><Name>RONDO</Name><FirstName>Paul</FirstName><DOB>1980-10-30</DOB></Employees></EMPLOYEES> ' 


CONV_DATA ORIG_DATA 'XML(*ALPHA=/EMPLOYEES/Employees/ID no.) DEST_DATA 'JSON' 


Returns DEST_DATA with the value '{"EMPLOYEES":{"Employees":{"ID no.":"52413","Name":"RONDO","FirstName":"Paul","DOB":"1980-10-30"}}}' 


Example 8

ORIG_DATA ='<?xml version="1.0" encoding="UTF-8" ?><EMPLOYEES> <Employees><ID no.>52413</ID no.><Name>RONDO</Name><FirstName>Paul</FirstName><DOB>1980-10-30</DOB></Salaries></EMPLOYEES' 


CONV_DATA ORIG_DATA 'XML(*ARRAY=/EMPLOYEES/Employees, *ALPHA=/EMPLOYEES/Employees/ID no.) '  DEST_DATA 'JSON' 


Returns DEST_DATA with the value ' {"EMPLOYEES":{"Employees":[{"ID no.":"52413","Name":"RONDO","FirstName":"Paul","DOB":"1980-10-30"}]}} ' 


Example 9


ORIG_DATA = '{"n1" : "valn1" , "2x" : "val2x"}'




CONV_DATA ORIG_DATA 'JSON(*DIGIT_NAME)' DATA_DEST 'XML'




Returns DEST_DATA with the value <?xml version="1.0" encoding="UTF-8" standalone="yes"?><Root><n1>valn1</n1><_DIGIT_2x>val2x</_DIGIT_2x>/Root>





↑ Top of page

  • Aucune étiquette