lr_eval_json

Creates a JSON object from a string or a file.

C Language

int lr_eval_json( "Buffer or Buffer/File = <buffer>", "JsonObject = <parameter name>" );

ExampleParameter Functions

Arguments

NameComments
Buffer A JSON string.
Buffer/FileThe path of the file that contains the JSON string.
JsonObjectThe name of the parameter to store the handle of the JSON object.

lr_eval_json parses a JSON string, creates a JSON object, and stores the handle of the object in a parameter.

This function is not recorded. You can insert it manually into your script.

Return Values

This function returns 0 on success and -1 on failure.

Parameterization

Parameterization is not applicable to this function.

Example

This script shows the usage of lr_eval_json.

TestEval()
{
	char* json_input = "{"
		"\"firstName\": \"John\","
		"\"lastName\": \"Smith\","
		"\"address\": {"
		"    \"streetAddress\":\"21 2nd Street\","
		"    \"city\":\"New York\","
		"    \"state\":\"NY\","
		"    \"postalCode\":\"10021\""
		"}"		
		"}";
	lr_save_string(json_input, "JSON_Input_Param");
	
	// Create a Json object from a string.
	lr_eval_json("Buffer={JSON_Input_Param}",
	             "JsonObject=json_obj_1", LAST);
	
	// // Create a Json object from a file.
	lr_eval_json("Buffer/File=store.json", 
	             "JsonObject=json_obj_2", LAST);
	
	return 0;
}
 

TestEval.c(16): Notify: Parameter Substitution: parameter "JSON_Input_Param" = "{"firstName": "John","lastName": "Smith","address": { "streetAddress":"21 2nd Street", "city":"New York", "state":"NY", "postalCode":"10021"}}"