JSON Management Codeunit

dreezdreez Member Posts: 72
Hello,

Up to this day I was using Newtonsoft.Json DotNet variables, but the problem is, that in AL it is not allowed to use DotNet variables.
There is a codeunit 5459 JSON Management available which has some external methods that I can use.

I want to store incoming JSON in the table similar to TB1236: JSON Buffer. I had to modify JSON Buffer's ReadFromText function a bit, so I would like to use some functions from JSON Management instead.
Here is the code from JSONBuffer.
ReadFromText(JsonText: Text)
JSONTextReader := JSONTextReader.JsonTextReader(StringReader.StringReader(JSONText));
IF JSONTextReader.Read THEN
  REPEAT
    INIT;
    "Entry No." += 1;
    Depth := JSONTextReader.Depth;
    TokenType := JSONTextReader.TokenType;
    "Token type" := TokenType;
    IF ISNULL(JSONTextReader.Value) THEN
      Value := ''
    ELSE
      SetValueWithoutModifying(FORMAT(JSONTextReader.Value));
    IF ISNULL(JSONTextReader.ValueType) THEN
      "Value Type" := ''
    ELSE
      "Value Type" := FORMAT(JSONTextReader.ValueType);
    Path := JSONTextReader.Path;
    INSERT;
  UNTIL NOT JSONTextReader.Read;
I am not quite sure if I can modify that code to get the same result with JSON Management Codeunit.
I know I can use given JSON Buffer Table, but I would like to know if it's possible to get the same result by using the codeunit.

So my question is: Is it possible? And if yes, then how?

Thank you for your time. ;)

Best Answer

Answers

Sign In or Register to comment.