Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>json2apexNew to Visual Studio Code? Get it now.
json2apex

json2apex

Akhil R

|
6 installs
| (0) | Free
Convert JSON to Apex classes with automatic inner class generation and static parsing support
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

JSON to Apex Converter

A Visual Studio Code extension that converts JSON to Apex classes with automatic inner class generation and static parsing support.

Features

  • Convert JSON to Apex classes with proper property types
  • Automatic generation of inner classes for nested objects
  • Static parse method using System.JSON.deserialize
  • Built-in test method with sample JSON
  • Support for arrays and nested objects
  • Sample value comments for better documentation
  • No explicit getters and setters (using direct property access)

Installation

  1. Open Visual Studio Code
  2. Go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X)
  3. Search for "JSON to Apex Converter"
  4. Click Install

Usage

  1. Open or create a JSON file in VS Code
  2. Select the JSON content you want to convert
  3. Right-click on the selected text
  4. Choose "Convert JSON to Apex" from the context menu
  5. Enter your desired Apex class name when prompted
  6. A new file will open with the generated Apex class

Example

Input JSON:

{
    "name": "John Doe",
    "age": 30,
    "isActive": true,
    "scores": [95, 87, 91],
    "address": {
        "street": "123 Main St",
        "city": "New York"
    }
}

Generated Apex class:

public class fromJSON {
    public String name;    //John Doe
    public Integer age;    //30
    public Boolean isActive;    //true
    public cls_scores[] scores;    //[95, 87, 91]
    public cls_address address;    //{street: 123 Main St, city: New York}

    class cls_address {
        public String street;    //123 Main St
        public String city;    //New York
    }

    public static fromJSON parse(String json) {
        return (fromJSON) System.JSON.deserialize(json, fromJSON.class);
    }

    static testMethod void testParse() {
        String json = ' {'+
            '       "name": "John Doe",'+
            '       "age": 30,'+
            '       "isActive": true,'+
            '       "scores": [95, 87, 91],'+
            '       "address": {'+
            '           "street": "123 Main St",'+
            '           "city": "New York"'+
            '       }'+
            '   }';
        fromJSON obj = parse(json);
        System.assert(obj != null);
    }
}

Features in Detail

Automatic Inner Class Generation

  • Nested objects are automatically converted to inner classes
  • Inner classes are prefixed with 'cls_'
  • Properties maintain their original types

Static Parsing

  • Includes a static parse method using System.JSON.deserialize
  • Easy to use: YourClass obj = YourClass.parse(jsonString);

Test Method

  • Automatically generates a test method
  • Includes sample JSON for testing
  • Basic assertion to verify parsing works

Property Types

  • String: for text values
  • Integer: for whole numbers
  • Decimal: for decimal numbers
  • Boolean: for true/false values
  • Custom arrays: for array values
  • Inner classes: for nested objects

Requirements

  • Visual Studio Code 1.85.0 or higher
  • Salesforce development environment (for using the generated Apex classes)

Contributing

Feel free to submit issues and enhancement requests!

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft