{"id":1746,"date":"2026-10-02T09:00:00","date_gmt":"2026-10-02T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/"},"modified":"2026-11-15T11:31:37","modified_gmt":"2026-11-15T06:01:37","slug":"json-in-apex-serialize-deserialize","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/","title":{"rendered":"JSON in Apex: Serialize, Deserialize and Parse API Data"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">JSON in Apex is how your code turns Salesforce data into text for an API, and turns API replies back into Apex objects. Almost every modern integration sends and receives JSON, so this skill sits under every callout and REST service you write. The built-in JSON class does most of the work in one line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, you will serialize records and wrapper classes, deserialize typed and untyped JSON, build JSON with JSONGenerator and avoid common parsing traps. It builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-collections-list-set-map\/\">Apex collections<\/a>, <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-rest-callouts-httprequest\/\">Apex REST callouts<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/\">Apex REST services<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is JSON in Apex?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JSON, short for JavaScript Object Notation, is a text format made of key and value pairs, lists and nested objects. JSON in Apex means using the JSON class and its helpers to convert between that text and Apex types. Serializing turns Apex into JSON text, and deserializing turns JSON text into Apex.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of packing for a move. Serializing is packing furniture into labelled boxes, so it travels safely. Deserializing is unpacking those boxes in the new house and putting each item back in the right room.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why JSON in Apex Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every API speaks some data format, and today it is mostly JSON. Here is why JSON in Apex matters at Bright Path Tutors.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, LearnHub expects student data as a JSON body.<\/li>\n\n<li>Also, PayQuick returns payment details as nested JSON.<\/li>\n\n<li>Next, the partner course API sends JSON to an Apex REST service.<\/li>\n\n<li>Platform event payloads and logs are often stored as JSON text.<\/li>\n\n<li>Finally, LWC and Apex exchange data that Salesforce turns into JSON.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So clean JSON in Apex keeps every integration simple and reliable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How JSON in Apex Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Working with JSON in Apex follows a short path. First, you design an Apex class whose fields match the JSON keys. Next, for outbound data, you fill the class and call JSON.serialize to get text. Then you send that text as a callout body. After that, for inbound data, you call JSON.deserialize with the class type. Finally, when the structure is unknown, you use deserializeUntyped and read the result as maps and lists.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-diagram-1-1024x640.png\" alt=\"JSON in Apex diagram showing design, serialize, send, deserialize and untyped parsing\" class=\"wp-image-1744\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">How JSON moves in and out of Apex.<\/figcaption><\/figure>\n\n\n<h3 class=\"wp-block-heading\">JSON.serialize and serializePretty<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JSON.serialize turns any Apex object into compact JSON. Also, serializePretty adds line breaks for easy reading in debug logs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JSON.deserialize<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JSON.deserialize(text, MyClass.class) creates a typed object. Because the result is an Object, you cast it to your class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JSON.deserializeStrict<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This version fails if the JSON has keys your class does not have. So use it when the contract must match exactly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JSON.deserializeUntyped<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This returns Map&lt;String, Object&gt; and List&lt;Object&gt; structures. It suits flexible JSON, although you must cast every value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JSONGenerator and JSONParser<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">JSONGenerator builds JSON step by step, and JSONParser reads it token by token. Use them only for unusual shapes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">JSON Class Methods at a Glance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below lists the methods you will use most.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Direction<\/th><th>Use for<\/th><\/tr><\/thead><tbody><tr><td>JSON.serialize(obj)<\/td><td>Apex to JSON<\/td><td>Callout bodies<\/td><\/tr><tr><td>JSON.serialize(obj, true)<\/td><td>Apex to JSON<\/td><td>Skipping null fields<\/td><\/tr><tr><td>JSON.deserialize(text, Type)<\/td><td>JSON to Apex<\/td><td>Known structures<\/td><\/tr><tr><td>JSON.deserializeStrict(text, Type)<\/td><td>JSON to Apex<\/td><td>Exact contracts<\/td><\/tr><tr><td>JSON.deserializeUntyped(text)<\/td><td>JSON to maps<\/td><td>Unknown structures<\/td><\/tr><tr><td>JSON.createGenerator(true)<\/td><td>Build JSON<\/td><td>Custom shapes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Typed vs Untyped Deserialization<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares the two main ways to read JSON.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Typed (wrapper class)<\/th><th>Untyped (maps and lists)<\/th><\/tr><\/thead><tbody><tr><td>Code safety<\/td><td>Compiler checks fields<\/td><td>Casts at runtime<\/td><\/tr><tr><td>Readability<\/td><td>High<\/td><td>Lower with deep nesting<\/td><\/tr><tr><td>Handles unknown keys<\/td><td>Ignores them<\/td><td>Yes<\/td><\/tr><tr><td>Setup<\/td><td>Write a class<\/td><td>None<\/td><\/tr><tr><td>Best for<\/td><td>Stable APIs<\/td><td>Changing or dynamic JSON<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is simple. Use typed wrappers for APIs with a stable contract. Use untyped parsing for small or unpredictable parts.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-diagram-2-1024x640.png\" alt=\"JSON in Apex diagram comparing typed and untyped deserialization\" class=\"wp-image-1745\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Typed vs untyped deserialization.<\/figcaption><\/figure>\n\n\n<h2 class=\"wp-block-heading\">A Real JSON in Apex Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s use JSON in Apex for PayQuick at Bright Path Tutors. Salesforce sends a payment request and reads a nested reply.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Wrapper Classes and Serialization<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public class PayQuickModels {\n    public class PaymentRequest {\n        public String reference;\n        public Decimal amount;\n        public String currencyCode;\n        public String notes;          \/\/ optional\n    }\n    public class PaymentReply {\n        public String id;\n        public String status;\n        public Card card;\n    }\n    public class Card {\n        public String brand;\n        public String last4;\n    }\n}\n\n\/\/ Run in Anonymous Apex after saving the class\nPayQuickModels.PaymentRequest req = new PayQuickModels.PaymentRequest();\nreq.reference = 'ENR-0042';\nreq.amount = 5000;\nreq.currencyCode = 'INR';\nString body = JSON.serialize(req, true);   \/\/ true = skip null fields\nSystem.debug(body);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The wrapper fields match PayQuick&#8217;s JSON keys. Because notes is null, the second argument leaves it out of the body.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the debug output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\"reference\":\"ENR-0042\",\"amount\":5000,\"currencyCode\":\"INR\"}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Typed and Untyped Parsing<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Anonymous Apex\nString replyJson = '{\"id\":\"PQ-88\",\"status\":\"captured\",\"card\":{\"brand\":\"Visa\",\"last4\":\"4242\"},\"meta\":{\"risk\":12}}';\n\nPayQuickModels.PaymentReply reply =\n    (PayQuickModels.PaymentReply) JSON.deserialize(replyJson, PayQuickModels.PaymentReply.class);\nSystem.debug(reply.status + ' with ' + reply.card.brand + ' ' + reply.card.last4);\n\nMap&lt;String, Object&gt; raw = (Map&lt;String, Object&gt;) JSON.deserializeUntyped(replyJson);\nMap&lt;String, Object&gt; meta = (Map&lt;String, Object&gt;) raw.get('meta');\nInteger risk = (Integer) meta.get('risk');\nSystem.debug('Risk score: ' + risk);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Typed parsing reads the nested card through the Card class and ignores the extra meta key. Then untyped parsing picks out meta.risk, which the wrapper does not model.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the debug output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>captured with Visa 4242\nRisk score: 12<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">JSON in Apex and Reserved Words<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Some JSON keys, such as &#8220;currency&#8221; or &#8220;limit&#8221;, clash with Apex reserved words. So rename the field, like currencyCode, and replace the key in the text before parsing, or use JSONParser. For outbound JSON, build a Map&lt;String, Object&gt; with the exact key instead.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with JSON in Apex<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Forgetting to cast the result of JSON.deserialize.<\/li>\n\n<li>Using deserializeStrict when the API often adds new keys.<\/li>\n\n<li>Casting untyped numbers to the wrong type, such as Decimal to Integer.<\/li>\n\n<li>Serializing full sObjects and sending fields the API does not need.<\/li>\n\n<li>Ignoring reserved words in JSON keys.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for JSON in Apex<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep one models class per external API.<\/li>\n\n<li>Use typed wrappers for stable contracts.<\/li>\n\n<li>Skip nulls when the API rejects empty fields.<\/li>\n\n<li>Log the raw JSON on errors, without personal data.<\/li>\n\n<li>Write tests with real sample JSON from the API docs.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Parse a LearnHub reply that holds a list of courses, each with a title and progress percentage. Hint: create a wrapper with a List of an inner Course class, then deserialize the whole reply in one call.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Interview Questions on JSON in Apex<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JSON questions appear in almost every integration interview. Here are the 22 questions asked most about JSON in Apex.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Questions on JSON in Apex<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is JSON?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is a text format of keys, values, lists and nested objects, so systems can exchange data easily.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: How do you convert an Apex object to JSON?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call JSON.serialize, which returns a JSON string.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: How do you convert JSON to an Apex object?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call JSON.deserialize with the class type, then cast the result.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: What does deserializeUntyped return?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It returns maps and lists, so you read values with get and casts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: What does serializePretty do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It adds indents and line breaks, so the JSON is easy to read in logs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: What happens to extra keys with JSON.deserialize?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They are ignored, so the call still succeeds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: What does deserializeStrict do differently?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It throws an error if the JSON has keys that the class lacks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code and Scenario Questions on JSON in Apex<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: How do you skip null fields when serializing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pass true as the second argument to JSON.serialize.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: How do you read a nested value with untyped parsing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cast each level to Map&lt;String, Object&gt;, then call get on the next key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: How do you handle a JSON key named &#8220;currency&#8221;?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Rename the field in Apex and swap the key in the text, or use JSONParser.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: How do you parse a JSON array at the top level?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Deserialize into List&lt;MyClass&gt;.class, or use deserializeUntyped and cast to List&lt;Object&gt;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: Why does casting an untyped number to Integer sometimes fail?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because decimals arrive as Decimal, so cast to Decimal first when values may have fractions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: When would you use JSONGenerator?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you must build JSON with dynamic keys or a shape that no class models well.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: How do you test JSON parsing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use sample JSON strings in a test method and assert the parsed values.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Questions on JSON in Apex<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: How does Salesforce serialize sObjects?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It includes an attributes block with type and url, plus the queried fields.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: How do you avoid heap problems with large JSON?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Request smaller pages from the API, and parse in async Apex with its larger heap.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: What is JSONParser good for?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reading very large or irregular JSON token by token without building a full object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: How do you keep parsing safe when the API adds fields?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use JSON.deserialize, which ignores unknown keys, instead of deserializeStrict.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: How do dates travel in JSON?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As ISO 8601 strings, which Apex maps to Date or Datetime fields.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: How does an Apex REST service receive JSON?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce maps body keys to method parameters, or you parse requestBody yourself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: Why use wrapper classes instead of maps?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because the compiler checks fields, so typos fail early instead of at runtime.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: How do you send a map with exact key names?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Build a Map&lt;String, Object&gt; and serialize it, so keys stay as written.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/apex-ref\/references\/apex-ref\/apex-class-system-json.html\" target=\"_blank\" rel=\"noopener noreferrer\">JSON Class (Apex Reference Guide)<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/apex-dev\/references\/apex-dev\/apex-callouts-http.html\" target=\"_blank\" rel=\"noopener noreferrer\">Invoking HTTP Callouts (Apex Developer Guide)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use JSON in Apex through the JSON class, for both directions.<\/li>\n\n<li>Serialize wrappers for callout bodies, and skip nulls when needed.<\/li>\n\n<li>Deserialize typed for stable APIs and untyped for flexible data.<\/li>\n\n<li>Rename fields that clash with reserved words.<\/li>\n\n<li>Test parsing with real sample JSON.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Events can stream out of Salesforce in real time too. Next, read our guide to <a href=\"https:\/\/swapnilzambare.com\/blog\/pub-sub-api-salesforce-grpc\/\">the Pub\/Sub API<\/a>, the last post of Level 9.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JSON in Apex is how your code turns Salesforce data into text for an API, and turns API replies back into Apex objects. Almost&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1743,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[246,8,96],"tags":[98,81,26],"swapz_series":[],"class_list":["post-1746","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-integration-apis","category-salesforce","category-salesforce-developer","tag-apex","tag-integration","tag-intermediate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JSON in Apex: Serialize and Deserialize Simply<\/title>\n<meta name=\"description\" content=\"JSON in Apex explained simply: JSON.serialize, deserialize, deserializeUntyped, wrapper classes, JSONGenerator, reserved words and 22 interview Q&amp;A.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JSON in Apex: Serialize and Deserialize Simply\" \/>\n<meta property=\"og:description\" content=\"JSON in Apex explained simply: JSON.serialize, deserialize, deserializeUntyped, wrapper classes, JSONGenerator, reserved words and 22 interview Q&amp;A.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-02T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T06:01:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"JSON in Apex: Serialize, Deserialize and Parse API Data\",\"datePublished\":\"2026-10-02T03:30:00+00:00\",\"dateModified\":\"2026-11-15T06:01:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/\"},\"wordCount\":1535,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/json-in-apex-serialize-deserialize-featured.png\",\"keywords\":[\"Apex\",\"Integration\",\"Intermediate\"],\"articleSection\":[\"Integration and APIs\",\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/\",\"name\":\"JSON in Apex: Serialize and Deserialize Simply\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/json-in-apex-serialize-deserialize-featured.png\",\"datePublished\":\"2026-10-02T03:30:00+00:00\",\"dateModified\":\"2026-11-15T06:01:37+00:00\",\"description\":\"JSON in Apex explained simply: JSON.serialize, deserialize, deserializeUntyped, wrapper classes, JSONGenerator, reserved words and 22 interview Q&A.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/json-in-apex-serialize-deserialize-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/json-in-apex-serialize-deserialize-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"JSON in Apex featured image: title card with an integration code example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/json-in-apex-serialize-deserialize\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JSON in Apex: Serialize, Deserialize and Parse API Data\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JSON in Apex: Serialize and Deserialize Simply","description":"JSON in Apex explained simply: JSON.serialize, deserialize, deserializeUntyped, wrapper classes, JSONGenerator, reserved words and 22 interview Q&A.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/","og_locale":"en_US","og_type":"article","og_title":"JSON in Apex: Serialize and Deserialize Simply","og_description":"JSON in Apex explained simply: JSON.serialize, deserialize, deserializeUntyped, wrapper classes, JSONGenerator, reserved words and 22 interview Q&A.","og_url":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-10-02T03:30:00+00:00","article_modified_time":"2026-11-15T06:01:37+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"JSON in Apex: Serialize, Deserialize and Parse API Data","datePublished":"2026-10-02T03:30:00+00:00","dateModified":"2026-11-15T06:01:37+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/"},"wordCount":1535,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-featured.png","keywords":["Apex","Integration","Intermediate"],"articleSection":["Integration and APIs","Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/","url":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/","name":"JSON in Apex: Serialize and Deserialize Simply","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-featured.png","datePublished":"2026-10-02T03:30:00+00:00","dateModified":"2026-11-15T06:01:37+00:00","description":"JSON in Apex explained simply: JSON.serialize, deserialize, deserializeUntyped, wrapper classes, JSONGenerator, reserved words and 22 interview Q&A.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/json-in-apex-serialize-deserialize-featured.png","width":2400,"height":1260,"caption":"JSON in Apex featured image: title card with an integration code example"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/json-in-apex-serialize-deserialize\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JSON in Apex: Serialize, Deserialize and Parse API Data"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1746","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1746"}],"version-history":[{"count":1,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1746\/revisions"}],"predecessor-version":[{"id":2337,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1746\/revisions\/2337"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1743"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1746"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}