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
chikkuchikku 

How to create JSON Generator with apex?

I'm new to Apex. I have JSON data I need to convert to JSON Generator.
Can you please help me out?
Contact app = [select Id, Name from Contact ];
{
  "CustomerID": 0,
  "CustomerType": 1,
  "Name": "callum, john",  (app.Name,app.LastName) like this i need in JSON Generator.
  "BranchID": 1,
  "CustomerAddress": [
    {
      "CustomerAddressID": 0,
      "CustomerID": 0,
      "Address": {
        "Address1": "Test",
        "TownCityID": 41037,
        "CountyID": null,
        "StateID": 41036,
        "CountryID": 4,
        "Country": "Australia"
      },
      "AddressTypeID": 1,
      "DateMovedIn": "11/09/2019",
      "IsPrimary": false
    }
  ],
  "Persons": [
    {
      "PersonID": 0,
      "Title": 1,
      "Gender": 0,
      "ForenamePartOne": "callum",
      "ForenamePartTwo": null,
      "ForenamePartThree": null,
      "Surname": "john",
      "DateOfBirth": "11/09/1970",
      "SocialSecurityNumber": "35",
      "telephone1": "",
      "telephone2": "",
      "telephone3": "6598307315"
    }
  ],
  "CorrespondenceName": "callum, john",
  "DateJoined": "11/09/2019"
}


 
VinayVinay (Salesforce Developers) 
Check below tools that can help you with conversion.

https://www.adminbooster.com/tool/json2apex
https://json2apex.herokuapp.com/

Please mark as Best Answer if above information was helpful.

Thanks,
Suraj Tripathi 47Suraj Tripathi 47
Hi,

You can use the below tool:-https://json2apex.github.io/
Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi