function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Creating JSON array in Apex


I'm looking for some function/utility/feature in Apex which will returns the JSON representation of a value. The return value should be a string containing the JSON representation of value.

We need to query some data from SF object and then pass on that data as a JSON string to a ExtJS (javascript library) to build a dynamic tree.


There is similar function available in PHP, is there anything similar to this in Apex as well?


Any pointers to this will be a great help.







The closest you'd get in Apex is currently ... Object.toString() (as evidenced by running some code and looking at System.Debug() statements). However, one of my favorite developers, Ron Hess, posted an example of how to do JSON on CodeShare: You might check it out and see if it suits your needs, or if you can at least build on it.