Transferring a JSON via Parameter into a DS

Discussions relating to the ScottKlement.com port of the open source YAJL JSON Reader/Generator. This includes the YAJL tool as well as the YAJLR4, YAJLGEN, YAJLINTO and YAJLDTAGEN add-ons from ScottKlement.com. http://www.scottklement.com/yajl/
Post Reply
Oliver_superU
Posts: 2
Joined: Thu Jul 31, 2025 8:34 am

Transferring a JSON via Parameter into a DS

Post by Oliver_superU »

Hello everyone,

I'm receiving a JSON as a parameter in this format:

The parameter will be received in the program as a long string.

{
"matricule": 258,
"plateforme": "DT",
"specifFonction": "XP3",
"palettes": [
{
"ssccr": "31623311010770289",
"codeEmballageSR": "6311930",
"typeDestinataire": "A",
"codeDestinataire": "30530",
"emballagesSupp": [
{ "code": "6311799", "qteEmballage": 1 },
{ "code": "6311211", "qteEmballage": 3 }
],
"count": 2
},
{
"ssccr": "31623311010770290",
"codeEmballageSR": "6311930",
"typeDestinataire": "A",
"codeDestinataire": "30531",
"emballagesSupp": [
{ "code": "6311799", "qteEmballage": 1 },
{ "code": "6311211", "qteEmballage": 3 }
],
"count": 2
}
],
"count": 2
}
So I'd like to insert this JSON into a DS. I think YAJL can do it.

Do you have a code example in free-form to help me?

Thank you
Oliver_superU
Posts: 2
Joined: Thu Jul 31, 2025 8:34 am

Re: Transferring a JSON via Parameter into a DS

Post by Oliver_superU »

this my code
but not compiling on the Data-Into

*#C CRTSQLRPGI DBGVIEW(*SOURCE) OBJ(
**FREE

Ctl-opt Debug Datedit(*YMD) DFTACTGRP(*NO) actgrp(*new) bnddir('YAJL')
option(*srcstmt: *nodebugio: *noshowcpy);

/copy yajl_h

Dcl-ds EmballageSupp_t Qualified Template;
code VarChar(20);
qteEmballage Int(10);
End-ds;

Dcl-ds Palette_t Qualified Template;
ssccr Char(20);
codeEmballageSR VarChar(20);
typeDestinataire Char(1);
codeDestinataire VarChar(10);
num_emballagesSupp Int(5);
emballagesSupp Likeds(EmballageSupp_t) Dim(20);
count Int(5);
End-ds;

Dcl-ds MatriculeInfo_t Qualified Template;
matricule Int(10);
plateforme VarChar(20);
specifFonction VarChar(20);
num_palettes Int(5);
palettes Likeds(Palette_t) Dim(50);
count Int(5);
End-ds;

// Déclaration de la structure de données principale pour stocker le JSON parsé
Dcl-ds MonJsonDs Likeds(MatriculeInfo_t);

// Variables de travail
Dcl-s pJsonInput Varchar(32767); // Simule le paramètre JSON entrant
Dcl-s JsonData Pointer; // Pointeur pour la mémoire allouée dynamiquement
Dcl-s JsonLen Int(10); // Longueur réelle de la chaîne JSON
Dcl-s i Int(10); // Compteur pour la boucle des palettes
Dcl-s j Int(10); // Compteur pour la boucle des emballages sup

// Simulation du JSON reçu en paramètre
// En réalité, 'pJsonInput' serait un paramètre de procédure/programme.
pJsonInput = '{ "matricule": 258, "plateforme": "DT", "specifFonction": "XP3", +
"palettes": [ {"ssccr": "31623311010770289", +
"codeEmballageSR": "6311930", "typeDestinataire": "A", +
"codeDestinataire": "30530", "emballagesSupp": +
[ { "code": "6311799", "qteEmballage": 1 }, { "code":"6311211", +
"qteEiballage": 3 } ], "count": 2 }, +
{ "ssccr": "31623311010770290", "codeEmballageSR":"6311930", +
"typeiestinataire": "A", "codeDestinataire": "30531", +
"emballagesSupp": [ { "code":"6311799", "qteEmballage": 1 }, +
{ "code": "6311211", "qteEmballage": 3 } ], "count": 2 } ], "count":2 }';


// Allouer de la mémoire pour le JSON reçu
JsonLen = %Len(pJsonInput);
JsonData = %Alloc(JsonLen);
// Copier le contenu du paramètre simulé dans la mémoire allouée
%Str(JsonData:JsonLen) = pJsonInput;

// Utilisation de DATA-INTO pour mapper le JSON à la structure de données principale
Data-Into MonJsonDs
%Data(JsonData: JsonLen)
%Parser('YAJLINTO' : 'case=lower + allowextra=yes + countprefix=num_');
Return;
Scott Klement
Site Admin
Posts: 899
Joined: Sun Jul 04, 2021 5:12 am

Re: Transferring a JSON via Parameter into a DS

Post by Scott Klement »

Try using the YAJLGEN command that comes with YAJL, it will help you get started in defining your data structure.

I don't understand why you are using pointers and %ALLOC and similar things, this doesn't make any sense in this context.
Post Reply