1

I have a class that I want to fill then pass to an event rule as payload. like this.

public class Payload
{
    public string Site {get;set;}
    public string Region {get;set}
    ....
}

now in my CDK I fill these with other values

var payload = new PayLoad()
payload.Site = "NY";
payload.Region = "1"
....

var _json = JsonSerializer.Serialize(payload )

Now, I want to pass this the RuleTargetInput for the event rule

eventRule.AddTarget(new LambdaFunction(fn, new LambdaFunctionProps
{
Event = RuleTargetInput.FromObject(_json )
}));

And the event shows something like this

"{"\Site\":\"NYC\",\"Region\"}"....

The lambda function does not like this payload. if I manually remove the backslashes then it works. is there a way with System.Text.Json to remove the backslashes on Serialize?

causita
  • 1,607
  • 1
  • 20
  • 32

1 Answers1

1

Looks like a json string is passed 'FromObject' as an object or FromText from a json serializer, the output will have the escape charactres "

according to this github issue Git Hub issue

So the solution is to convert to a dictionary then pass it to RuleTargetInput

var rootDictionary = new Dictionary<string, object>();
rootDictionary.Add("Site",item.Site);
rootDictionary.Add("Region",item.Region);
... other list to this

then

Event = RuleTargetInput.FromObject(rootDictionary)
causita
  • 1,607
  • 1
  • 20
  • 32