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
Manohar SF.ax1874Manohar SF.ax1874 

to check if json node exist

How can I check using APEX if a JSON node exist in the input as in below?

Payload1
{
            "lname": "l1",
            "fname": "f1"
}

Payload2 
{
            "lname": "l1"
}


Thanks
Manohar
Best Answer chosen by Manohar SF.ax1874
GlynAGlynA
You could use the String method "contains()", which will return true if the string contains the specified substring.

Or, you could use JSON.deserialize() to create a collection of objects and then see if the object you want exists, and what values it has.

Glyn Anderson
Sr Developer | System Analyst | ClosedWon | closedwon.com
Certified Developer | Certified Advanced Administrator
Blog: GlynATheApexGuy@blogspot.com
Twitter: @GlynAtClosedWon

All Answers

GlynAGlynA
You could use the String method "contains()", which will return true if the string contains the specified substring.

Or, you could use JSON.deserialize() to create a collection of objects and then see if the object you want exists, and what values it has.

Glyn Anderson
Sr Developer | System Analyst | ClosedWon | closedwon.com
Certified Developer | Certified Advanced Administrator
Blog: GlynATheApexGuy@blogspot.com
Twitter: @GlynAtClosedWon
This was selected as the best answer
Manohar SF.ax1874Manohar SF.ax1874
thanks for that Glyn, I overlooked the simple string method option and was looking using JSON.deserialize().