1

As per title, is there any way to convert from C/AL object to JSON object? If I'm not mistaken, some of the data types in C/AL can be converted straight to .NET object (string, int, etc) but I'm not sure which types are / are not.

I'm looking to transfer tables and query type variables to managed codes using JSON. Do I need to construct the whole JSON and serialize it before sending it over? Or is there anything simpler way?

I'm looking if there's any way to do something like this:

JsonConvert.Serialize(MyTableVariable);
JsonConvert.Serialize(MyQueryVariable);
Farid
  • 872
  • 1
  • 13
  • 30

1 Answers1

2

There is no standard way to convert record/query to json. Moreover you would never want to see all record's fields in json. Most probably you need only small subset of the fields. You need to create json manually.

You can use RecordRef/FieldRef types to iterate through fields of the record and export them into json fields. If you do this it will be universal for any record variable in the system. Not sure you can do the same with queries though. And you will need to handle each document individually.

Alternatively you can create an XMLPort for each designated record/document/query and use it to export data to xml first and then convert xml to json. But there may be issues with conversion itself and Nav's ports inflexibility (if you need conplex json structure).

Mak Sim
  • 2,148
  • 19
  • 30