Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Convert a json object to an Array list Using Rest

(0) ShareShare
ReportReport
Posted on by 67

I'm using a post method to post Inventory data to an Https site. I was able to create a json string that looks like this example:

{"CustomerKey": "112221124545412","partCode": "Items-1","Description":"Chips"}

however I need the string look like the following:

{

  "parts": "[\r\n      {\r\n         \"CustomerKey\": \"e3704b8b-a09a-4143-8bb5-81bce8d5af43\",\r\n         \"PartCode\": \"Part 2\",\r\n         \"Description\": \"Part Description\",\r\n         \"AlternateDescription\": \"\",\r\n         \"UnitOfMeasure\": \"Each\",\r\n         \"EffectiveDate\": null,\r\n         \"ExpiryDate\": null,\r\n         \"ThresholdQuantity\": 10,\r\n         \"Location\": \"4\",\r\n         \"Certified\": false,\r\n         \"Taxable\": false,\r\n         \"UnitPrice\": 0,\r\n         \"Quantity\": 0,\r\n         \"OrderedbutNotReceived\": 0\r\n      },\r\n      {\r\n         \"CustomerKey\": \"e3704b8b-a09a-4143-8bb5-81bce8d5af43\",\r\n         \"PartCode\": \"Part 3\",\r\n         \"Description\": \"Part Description\",\r\n         \"AlternateDescription\": \"\",\r\n         \"UnitOfMeasure\": \"Each\",\r\n         \"EffectiveDate\": null,\r\n         \"ExpiryDate\": null,\r\n         \"ThresholdQuantity\": 10,\r\n         \"Location\": \"4\",\r\n         \"Certified\": false,\r\n         \"Taxable\": false,\r\n         \"UnitPrice\": 0,\r\n         \"Quantity\": 0,\r\n         \"OrderedbutNotReceived\": 0\r\n      }\r\n   ]"

}

 

I'm guessing I need to convert the Json object to an Array list!! is that true and how would I do that?

Thanks for the help 

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Convert a json object to an Array list Using Rest

    Hello evbitas,

    Hope you have achieved your format.

    This is the format which I am trying to achieve in NAV 2016.  Can you please guide to achieve this and how did you achieve?

    {
    "bill": {
    "DocType": "INV",
    "DocNo": "104003",
    "DocDate": "08/02/2019",
    "ItemList": [
    {
    "ProductName": "TS1070I",
    "ProductDesc": "Manuafor eakers",
    "HsnCode": "85044090",
    "Quantity": "4",
    },
    {
    "ProductName": "TS1080I",
    "ProductDesc": "Manuafor eakers",
    "HsnCode": "85044090",
    "Quantity": "4",
    }
    ]
    }
    }

    Thanks,

  • Dietmar Wehinger Profile Picture
    67 on at
    RE: Convert a json object to an Array list Using Rest

    Thanks Andrey for your help. Your answers helped me a lot.

    Thanks again..

  • Verified answer
    Andrey Baludin Profile Picture
    3,941 on at
    RE: Convert a json object to an Array list Using Rest

    All objects are "Newtonsoft.Json.Linq.JObject"

    Array is Newtonsoft.Json.Linq.JArray

    By the way - I recommend you to take Codeunit 5459 JSON Management from NAV2018 and import it to your NAV2015 - it contains all the needed functions.

  • Ebitas Profile Picture
    82 on at
    RE: Convert a json object to an Array list Using Rest

    Thanks Andrey for the Info you provided. Yes I'm using Newtonsoft JSON dll.

    I'll try your solution and let you know.. Do you know what DotNet objects you used for JsonLineObject, JsonMainObject. , JsonArray ?

    Thanks again

  • Suggested answer
    Andrey Baludin Profile Picture
    3,941 on at
    RE: Convert a json object to an Array list Using Rest

    Hi!

    I don't know, how you create JSON in NAV 2015 (perhaps it's Newtonsoft JSON dll), but in business central process is next:

    1. You create Array element (as Json object) :

    JsonLineObject.Add('CustomerKey', '112221124545412');

    .......

    JsonLineObject.Add('OrderedbutNotReceived', '123124');

     

    2. You add element to Array :

    JsonArray.Add(JsonLineObject);

    (probably you will do step 1 and 2 in REPEAT cycle)

    3. You create Main JsonObject with your array:

    JsonMainObject.Add('parts', JsonArray.AsToken.AsArray());

     

    4. You send JsonMainObject to API.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics NAV (Archived)

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans