Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Replace a value in Json file

(1) ShareShare
ReportReport
Posted on by 16
Hi all,
I'm trying to replace a value in a Json file, but I don't find any example or documentation for AL Language. I've the following structure file:
 
{ /codeunitId/: 18121808,/functionName/ : /PrintDocMaya/,/parmInput/: [{/name/: /pDocumentType/,/value/: /1/},{/name/: /pDocumentNo/,/value/: /102046/},{/name/: /pFilePath/,/value/: /C:////Temp/////}],/parmOutput/: [{/name/: /Return/,/value/:/0/}]}
 
I would like to replace value /0/ from parmOutput for the element with name /Return/. How could this be done?
 
Thank you for your kindly replies.
 
DZ
  • dzaniboni Profile Picture
    dzaniboni 16 on at
    Replace a value in Json file
    I develop this solution:
    • create new Json Object for the section of the original Json object that I want to replace.
    • Create new Json Array to store in a Json array the new results for the outputParm section.
    • Add in the new Json Object the new keys and values
    • Add the new Json Object in the Json Array
    • Replace the Json array for the specific key (that's an array)
     
    Below the code:
     
            OutputJObject.Add('name', 'Return');
            OutputJObject.Add('value', O_DocFileName);
            OutputArray.Add(OutputJObject);
            JObject.Replace('parmOutput', OutputArray);
     
     
    Hope this you can help.
     
    DZ
     
     
  • Suggested answer
    gdrenteria Profile Picture
    gdrenteria 12,920 Most Valuable Professional on at
    Replace a value in Json file
    Hi
    In systemapplication is this code,  i hope this can help you. 
    BR
    Gerardo
  • dzaniboni Profile Picture
    dzaniboni 16 on at
    Replace a value in Json file
    Hi Mohamed,
    thank you for your reply but I'm able to create (from 0) or read a Json file. What I want is to know how to replace or modify an existing Json file (single values or properties).
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 10,169 Super User 2024 Season 2 on at
    Replace a value in Json file
    Hi dzaniboni
     
    I hope this can help you and give you some hints.
     
     
     
    Best regards,
    Mohamed Amine MAHMOUDI

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans