{"title":"JsonObject.Add(Text, Text) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/jsonobject/jsonobject-add-string-string-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/jsonobject/jsonobject-add-string-string-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/jsonobject/jsonobject-add-string-string-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Adds a new property to a JsonObject.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"JsonObject.Add(Text, Text) Method","slug":"jsonobjectaddtext-text-method","at":0,"chars":2883},{"level":2,"title":"Syntax","slug":"syntax","at":133,"chars":69},{"level":2,"title":"Parameters","slug":"parameters","at":202,"chars":171},{"level":2,"title":"Return Value","slug":"return-value","at":373,"chars":238},{"level":2,"title":"Remarks","slug":"remarks","at":611,"chars":566},{"level":2,"title":"Example 1","slug":"example-1","at":1177,"chars":394},{"level":2,"title":"Example 2","slug":"example-2","at":1571,"chars":642},{"level":2,"title":"Example 3","slug":"example-3","at":2213,"chars":532},{"level":2,"title":"Related information","slug":"related-information","at":2745,"chars":138}],"text":"# JsonObject.Add(Text, Text) Method\n> Version: _Available or changed with runtime version 1.0._\nAdds a new property to a JsonObject.\n## Syntax\n```al\n[Ok := ]  JsonObject.Add(Key: Text, Value: Text)\n```\n## Parameters\nJsonObject\nType: jsonobject-data-type\nAn instance of the jsonobject-data-type data type.\nKey\nType: ../text/text-data-type\nValue\nType: ../text/text-data-type\n## Return Value\n*[Optional] Ok*\nType: ../boolean/boolean-data-type\ntrue if the operation was successful; otherwise false. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nThe operation will fail if the object already contains a property with the given key.\nNote that text constants, such as labels or raw text values assigned in the source code, will be transformed by the compiler. All characters that require escaping in C# strings will be prefixed with the backslash symbol ('\\\\'). These characters include single and double quotes, backslashes, control characters (for example, line feed or tab). For more information, refer to https://learn.microsoft.com/dotnet/csharp/programming-guide/strings/#string-escape-sequences.\n## Example 1\nIn this example, the newline symbol '\\n' is changed to '\\\\\\\\n' when the value is added to the JSON object.\n```al\nlocal procedure AddMultilineTextValue()\nvar\n    TextValue: Label 'Multiline\\nValue';\n    JObj: JsonObject;\nbegin\n    JObj.Add('Key', TextValue);\nend;\n```\nWhen the code above is run, the variable JObj has the following value.\n```\n{\n    \"Key\": \"Multiline\\\\nValue\"\n}\n```\n## Example 2\nOne way to avoid redundant escaping is to use the JsonToken.ReadFrom(Text) method<../jsontoken/jsontoken-readfrom-string-method>\nIn the following example, the text value is assigned to a JsonToken variable, which is then appended to a JsonObject.\nNote the double quotes in the TextValue label.\n```al\nlocal procedure AddMultilineTextValue()\nvar\n    TextValue: Label '\"Multiline\\nValue\"';\n    JTok: JsonToken;\n    JObj: JsonObject;\nbegin\n    JTok.ReadFrom(TextValue);\n    JObj.Add('Key', JTok);\nend;\n```\nThe value of the variable JObj after running the code of this example is as follows.\n```\n{\n    \"Key\": \"Multiline\\nValue\"\n}\n```\n## Example 3\nAnother method is to add unescaped control characters to the AL text.\n```al\nlocal procedure AddMultilineTextValue()\nvar\n    Builder: TextBuilder;\n    JObj: JsonObject;\nbegin\n    Builder.AppendLine('Multiline');\n    Builder.Append('Value');\n    JObj.Add('Key', Builder.ToText());\nend;\n```\nIn the example above, TextBuilder.AppendLine method adds unescaped characters `0x0D` and `0x0A` at the end of the line, so the resulting JsonObject contains the escaped `\\r` `\\n` values.\n```\n{\n    \"Key\": \"Multiline\\r\\nValue\"\n}\n```\n## Related information\njsonobject-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}