Skip to content

ExtractJsonObject

Miriam McMahon edited this page Apr 27, 2023 · 6 revisions

Description

Convert a JSON text string into a JSON object. This object can be manipulated in embedded expressions.
Objects extracted using this component are JToken objects from the Newtonsoft Json.NET framework.
When retrieving a value from an object name-pair (ie "Name": "Robert"), refer to its Value (Name.Value).

Parameters

Parameter Name Description Type Resolved Type Required
JsonObjectName The string containing the JSON String String Yes
Name The name of the variable that will be assigned the JSON object String String Yes
ContainsSecret If true, suppress logging what was converted and sets parameter Name as secret. Defaults to false. Boolean Boolean No

Compatibility

This command was introduced in Safeguard 2.8

Examples

Example:

Retrieve Robert's info from the list of system users.

{
	"SetItem": {
		"Name": "SystemUsers",
		"Value": "[ { 'Name': 'Robert' , 'Id': '1' }, { 'Name': 'John' , 'Id': '2' }, { 'Name': 'Patrick' , 'Id': '3' } ]"
	}
},
{
	"SetItem": {
		"Name": "UserName",
		"Value": "Robert"
	}
},
{
	"ExtractJsonObject": {
		"JsonObjectName": "SystemUsers",
		"Name": "ParsedUsers"
	}
},
{
	"Log":{"Text": "%{ParsedUsers}%"}
},
{
	"SetItem": {
		"Name": "ParsedUser",
		"Value": "%{ ParsedUsers.FirstOrDefault(o => o.Name != null && o.Name.Value == UserName) }%"
	}
},
{
	"SetItem": {
		"Name": "UserId",
		"Value": "%{ ParsedUser.Id.Value }%"
	}
},
{
	"Log":{"Text": "%UserId%"}
}