Questions tagged [json]

JSON, or JavaScript Object Notation, is an open standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. It is used primarily to transmit data between a server and web application, as an alternative to XML.

Filter by
Sorted by
Tagged with
68 votes
5 answers
35k views

How do you deserialize json properties that are reserved words in Apex?

Is there any way to deserialize JSON into an object using JSON.deserialize if some of the property names in the JSON are reserved words in Apex? I want to do something like this: string jsonString = '{...
Greg Grinberg's user avatar
32 votes
1 answer
59k views

How do I parse a JSON map into an Apex Map?

I am trying to parse the following JSON format into a Object. { "info1": "blah blah", "info2": "blah blah2", "info3": 1391673663, "info4": "blah4", "info5": { "AAA": 0.1, "BBB": 0.3,...
kitokid's user avatar
  • 1,738
27 votes
4 answers
10k views

Unit tests that need more than one WebServiceMock

I'm dealing with an odd situation where I need to call Webservice A to authenticate to Webservice B and Webservice C, all with different endpoints. I know how to setup mocks to test B and C ...
Mike Chale's user avatar
  • 13.3k
26 votes
2 answers
29k views

System.JSONException: Apex Type unsupported in JSON: Object

I was trying to parse json to apex but i was getting System.JSONException: Apex Type unsupported in JSON: Object My apex code was public class patdetils77 { //public String ...
Rajasekhar's user avatar
  • 1,561
26 votes
2 answers
26k views

How do I get started working with JSON in Apex?

This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through ...
24 votes
5 answers
17k views

Can AMPScript parse JSON?

Using AMPScript to parse an XML feed. Client is switching to JSON. Is there something similar to BuildrowsetfromXML() for JSON in AMPScript? I am confined to using the members login area and not an ...
xtianjs's user avatar
  • 341
22 votes
1 answer
6k views

Exclude properties from Apex class when serializing to JSON

Is it possible to delete class properties dynamically in Apex Example: public class BananaHolder() { public boolean isRipe; public boolean isDelicious; public integer ...
GrayB's user avatar
  • 702
21 votes
2 answers
2k views

What are the different capabilities between the @RemoteAction serializer and JSON.serialize?

I've been working quite a bit with @RemoteAction methods and have noticed there seem to be a few inconsistencies between what's allowed in the apex JSON.(de)serialize methods and what the automatic ...
ca_peterson's user avatar
  • 22.9k
21 votes
2 answers
3k views

deserializing JSON to object: different behavior in unit test vs API?

So let's say I've got a class that looks like this: public class APIParams { public String name; public String category; public Boolean taxable = false; } Then I have a ...
mscholtz's user avatar
  • 1,324
19 votes
1 answer
86k views

How to deserialize a JSON String to Apex

How can I deserialize this json object: { "response": { "count": 1, "benchmark": 0.22567009925842, "requests": [ { "request": { ...
codeSlayer's user avatar
19 votes
1 answer
42k views

JSON: Cannot deserialize instance of date from VALUE_STRING

I'm officially breaking up with Salesforce Date parsing. This has got to be the most frustrating thing. I have the following date in a JSON string (full JSON below): 2017-06-03T10:34:24.000Z But ...
ZAR's user avatar
  • 2,033
19 votes
1 answer
1k views

Aura vs Apex - Deserialization and Interface discrepancy (Major rewrite with git repo)

Question rewritten and complete example code provided I am trying to write test methods for an aura implementation but am running into a roadblock where the JSON serialization/deserialization between ...
Eric's user avatar
  • 54.1k
18 votes
1 answer
28k views

How can I return JSON object from REST service?

I used JSONGenerator to generate a customized JSON String. I know I can return sObject or String using Salesforce REST. But now I am sure I do not want to return sObject because I want the customized ...
Jie's user avatar
  • 449
18 votes
1 answer
5k views

JSON.Serialize method not returning null fields

I have been using JSON.Serialize method extensively in one of customer's project. Today salesforce has started rolling out Spring '13 release on sandboxes. My customer's sandbox( cs11) is not listed ...
Ishan Kumar's user avatar
16 votes
3 answers
39k views

Deserialize JSON to SObject

Following code is giving me common.apex.runtime.impl.ExecutionException String jsonText = '{"Data": {"attributes": {"type": "Contact"},"Id": "0036100000JUXKkAAP","Description": "","LastName": "...
Nikola J.'s user avatar
  • 203
15 votes
1 answer
16k views

Write a generic JSON-serializable Parameters class without hitting "Apex Type unsupported in JSON: Object"

I need to easily serialize (save as long text field in database) and deserialize (convert back to a class) a parameter list in Apex of String -> Object value pairs. My first idea was just to write a ...
Robert Sösemann's user avatar
15 votes
1 answer
2k views

Bug? Why doesn't JSON.serialize support DescribeSObjectResult?

JSON.serialize supports DescribeFieldResult, meaning that I can do this: return JSON.serialize(Account.Name.getDescribe()); However, when I try to serialize the SObject itself, I experience an ...
sfdcfox's user avatar
  • 487k
15 votes
3 answers
25k views

Issue in parsing JSON when special characters are included

I have a Json file which has some special character as below:- { "TXT1": "Tést Data", "TXT2": "can®." }, The Special character (é.®) gives me a error BLOB is not a valid UTF-8 string while ...
SFDC Learner's user avatar
14 votes
1 answer
11k views

How to JSON.serialize not including null values

I have an issue. I have a class with few Strings public class DopplerJSONSerializer { public String name; public String email; } In some, I need to serialize and use only the name String in ...
BoDiE2003's user avatar
  • 437
14 votes
1 answer
6k views

How do I use Type.forName to deserialize a generic list of SObjects?

When the new Apex type methods were added in Summer '12, it was possible to do Type t = Type.forName('MyClass'); MyClass newObj = (MyClass)t.newInstance(); What is the equivalent when I want to ...
metadaddy's user avatar
  • 16.4k
14 votes
2 answers
2k views

Can create an Instance of Abstract Class, Salesforce Bug?

I was playing with Apex and stumbled upon this. Created an Abstract Class and made the constructor as private, so that noone can create an instance of it. This works just fine during compilation. it ...
Pranay Jaiswal's user avatar
13 votes
1 answer
1k views

What is the correct JSON/Apex Strategy?

Summary I'm having a lot of trouble deserializing a JSON file into apex. The problem is not in how to deserialize a JSON string, but rather what type of apex objects I should be using. I don't come ...
ZAR's user avatar
  • 2,033
13 votes
3 answers
2k views

Use JSON serialization to get around parameter limitations for future methods?

Future methods can only take primitives or collections of primitives as parameters. To get around this you could serialize Sobjects (or classes) to a string and then deserialize them in the future ...
Greg Grinberg's user avatar
12 votes
4 answers
17k views

How to remove attributes before JSON is sent from Custom REST Apex?

I get back JSON like the following: { Id = a0Ef0000002TPKVEA4; Name = a0Ef0000002TPKV; attributes = { type = "Market__c"; url ...
Bradley Thomas's user avatar
12 votes
1 answer
2k views

What Are saveRefs and resolveRefs?

I'm trying to find the definition for saveRef and resolveRef. I'm seeing these attributes in my Json plan files. What do they mean?
Bethany's user avatar
  • 133
12 votes
1 answer
6k views

Is there a way to get the SOQL behind a report?

I have a (reasonably) Year on Year analysis summary report that I use in Salesforce and I would like to create this report in SOQL or at least create the SOQL equivelant to return the same results, ...
Bartley's user avatar
  • 5,237
12 votes
2 answers
9k views

Apex - get values in nested JSON

I have some JSON being returned, but getting the values deeply nested is very annoying. { "Result":"1", "Matches":[ { "BioInformation":{ "BirthDate":"1987-09-13T05:00:00", ...
JimKasper99's user avatar
12 votes
2 answers
987 views

Comparison fails when converting Opportunity from/to JSON

I am facing an issue when converting an Opportunity to and then from JSON. If I put that in a test, the assertion fails when comparing both Opportunities. Here is my code: Test case: static ...
Juan Alvarez's user avatar
11 votes
2 answers
5k views

Why use JSON.serialize in @RemoteAction return statement

I can't figure out why in an @RemoteAction method you would want to JSON.serialize the object being returned? I see this in a lot of code and I'm trying to understand the reasoning. I thought @...
Christian Anderson's user avatar
11 votes
1 answer
11k views

Why is String.valueOf(Blob) different that Blob.toString()?

I am working on a REST Service that will desiralize the request body and interpret it. My understanding was that calling String.valueOf(objectInstance) would just call objectInstance.toString(). ...
Adrian Larson's user avatar
  • 150k
11 votes
2 answers
3k views

Parse JSON into Lead

I'm trying to parse a JSON response and create Lead records from it. The JSON is basically formatted as follows. Note, that this is not the complete data being parsed but is the general format of data....
user10445's user avatar
  • 113
10 votes
2 answers
18k views

JSON.deserializeUntyped() not parsing the whole JSON

I am trying to parse a complex JSON String using JSON.deserializeUntyped(). It parses the first level elements correctly but the second level elements come back as type ANY, even though I am expecting ...
Amit's user avatar
  • 313
10 votes
2 answers
1k views

Unfamiliar Syntax

I came across the following code online: @future(callout=true) public static void runWarehouseEquipmentSync(){ Http http = new Http(); HttpRequest request = new HttpRequest(); request....
Gabriel Rivera's user avatar
10 votes
4 answers
34k views

how to parse the JSON object in salesforce

how to parse the json string . here multiple contact,multiple postalcode and mulitple contactnumber .how can i get the values from this json output.like list of contacts,list of postalcode and list of ...
Kittu's user avatar
  • 113
10 votes
1 answer
8k views

What is the correct JSON to deserialize a map of sObjects?

I'm trying to store a map of sObjects in a static resource. I want to be able to store default values for test setup methods. I was able to get it working with the following JSON in the static ...
Greg Grinberg's user avatar
10 votes
2 answers
1k views

How to Deserialize AggregateResults?

Is it possible to deserialize AggregateResults? If not, why? When I try it the regular way, all my aggregate results are empty: List<AggregateResult> arList = [SELECT Name FROM Account GROUP BY ...
itsmebasti's user avatar
  • 6,399
10 votes
2 answers
10k views

JSON.deserialize Array of Objects

I'm trying use the Box 2.0 API which returns everything in JSON. This is great because I can use JSON.deserialize. I've run into one issue when getting the folder and file structure. Box returns it as ...
Daniel Hoechst's user avatar
9 votes
3 answers
5k views

Accessing Static Resource Contents from Lightning JS Controller

I am attempting to set the value of a lightning component attribute with the type JSON to the contents of a JSON static resource file. I am using the following to set the attribute from the client ...
dannymorty's user avatar
9 votes
1 answer
3k views

APEX ENUM Serialize to and Deserialize from JSON

I have APEX classes defined with enum properties that are to be serialized into JSON. Also, I am reading in JSON and deserializing them back to my defined classes. To make the enum properties work ...
Joe's user avatar
  • 93
9 votes
4 answers
4k views

How do you deserialize json into the correct virtual class?

Let's say I have a virtual class and two classes that extend it and I am getting a JSON response that could be either one of those classes. Is there a way to deserialize the JSON into the appropriate ...
Greg Grinberg's user avatar
9 votes
2 answers
15k views

How to store and JSON-serialize Map of Objects AND SObjects

This question is an extension to Write a generic JSON-serializable Parameters class without hitting “Apex Type unsupported in JSON: Object” where I learned how to serialize a Map to and from JSON. My ...
Robert Sösemann's user avatar
9 votes
2 answers
3k views

How to deserialize JSON to a class where the same variable name has different data types?

I am trying to deserialize some JSON to a class using JSON.deserialize. My JSON looks like this { "type": "GeometryCollection", "geometries": [ { "type": "Point", ...
Sam Maton's user avatar
  • 175
9 votes
1 answer
3k views

JSON.Serialize method not returning null fields (part deux)

My question is related to the question JSON.Serialize method not returning null fields in that I'm having the same issue but based on the solution, I'm unable to get my code to use version 27 (maybe I'...
Bob's user avatar
  • 111
8 votes
2 answers
29k views

Serialize a Map into a specific JSON object

I built a Map and serialized it into a JSON object, my code below: Map<String,List<String>> mapTypeSubType= new Map<String,List<String>>(); if(actionPlanB2C.size()>0){ ...
L.benedettini's user avatar
8 votes
1 answer
10k views

Method does not exist or incorrect signature: JSON.serialize(List<SObject>)

My org instance is https://ap1.salesforce.com/ Looks like it is an issue. List<String> myArray = new List<String>(); for(Integer i=0;i<10;i++) { myArray....
Ratan Paul's user avatar
  • 22.6k
8 votes
3 answers
3k views

How to create a recursive method in Apex which takes a dot notation string and convert it into Hierarchical Map/Json?

I'm trying to create a utility class/method where a certain method will accept a list of Strings - each string will be constructed as follows: "Root.Parent.Child... N" This string can be N long (or ...
sfdx bomb's user avatar
  • 1,661
8 votes
3 answers
4k views

JSON deserialize from another managed package

In Salesforce if you try and do this: JSON.serialize(data); where data is an instance of a global Apex class in another managed package it will fail. This seems like a completely arbitrary and ...
NickJ's user avatar
  • 670
8 votes
1 answer
35k views

How to serialize an object as JSON?

I have an object that's pretty extensive (lots of properties and child relationships). I'd like to serialize it. So I am doing the following: Proposal__c proposal = (Proposal__c) getRecord(); ...
AngryHacker's user avatar
  • 1,481
8 votes
2 answers
2k views

Cannot deserialize JSON as abstract type

When running a test that's deserializing a JSON string, I get the error message: Cannot deserialize JSON as abstract type: TestController.Item The JSON contains a list of objects which is abstract ...
Sabrina's user avatar
  • 243
8 votes
3 answers
53k views

JSON and escaped double quote

I'm currently making a callout to a 3rd party vendor and I'm getting a huge response. What is currently messing me up is this section: "MessageSeq":13,"Description":"config ...
Double A's user avatar
  • 2,123

1
2 3 4 5
30