web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

How to iterate over JSON array in Navison 2018 using C/AL

(0) ShareShare
ReportReport
Posted on by 256

Hi All,

I need to iterate over JSONArray in Nav2018, following is the JSON Array snippet.

JSON Data:

{
"return": [
{
"id": 1,
"first_name": "aaa",
"last_name": "ddd",
},
{
"id": 2,
"first_name": "bbb",
"last_name": "eee",
},
{
"id": 3,
"first_name": "ccc",
"last_name": "ttt",
}
]
}

Here I need to insert each "id" data like id, first_name,last_name as a row in the database table.

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    I Gusti Made Ari Profile Picture
    3,608 on at

    Hi, you can use codeunit JSONManagement to do that .

    Sample code :

    //Create JSONArray String
    JSONManagement.InitializeFromString(JsonString); JSONManagement.GetJSONObject(JObject); ArrayString := JObject.SelectToken('return').ToString;
    //Read and Parse JSONArray CLEAR(JSONManagement); CLEAR(JObject); JSONManagement.InitializeCollection(ArrayString); JSONManagement.GetJsonArray(JSONArray);
    //loop and can do insert FOREACH JObject IN JSONArray DO BEGIN MESSAGE('%1 %2 %3', JObject.GetValue('id') , JObject.GetValue('first_name'), JObject.GetValue('last_name') ); END; Name DataType Subtype Length JSONManagement Codeunit JSON Management JSONArray DotNet Newtonsoft.Json.Linq.JArray.'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' JObject DotNet Newtonsoft.Json.Linq.JObject.'Newtonsoft.Json' ArrayString Text


  • mimran Profile Picture
    15 on at

    Thanks, This is helpful.

  • Suggested answer
    NeoMatrix Profile Picture
    256 on at

    Thank for the Reply. It's works perfectly.

  • Suggested answer
    NeoMatrix Profile Picture
    256 on at

    thanks

  • JeroenK Profile Picture
    15 on at

    Hi guys,

    For those who running on 2017 nav. You don't really need the JSON manager codeunit.

    IF lJSONString <> '' THEN
    lJObject := lJObject.Parse(FORMAT(lJSONString));

    lArrayString := lJObject.SelectToken('return').ToString;
    CLEAR(lJObject);
    lJsonArray := lJsonArray.Parse(lArrayString);

    FOREACH lJObject IN lJsonArray DO BEGIN
    MESSAGE('%1 %2 %3', lJObject.GetValue('id'),
    lJObject.GetValue('first_name'),
    lJObject.GetValue('last_name'));
    END;

    lArrayString = Text

    lJSONString = Text

    lJsonArray = DotNet Newtonsoft.Json.Linq.JArray.'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

    lObject = DotNet Newtonsoft.Json.Linq.JObject.'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans