title: Pass Json string to AWS Lambda in Step Function - JsonReaderException error
body: <p>I am attempting to use a AWS Lambda function in a Step Function. The Lambda Function works correctly when the it is tested individually and the json input is escaped. However when the input is passed to the lambda function through a step function, I am getting a JsonReaderException error. What am I doing wrong? Would the community know of a workaround for this issue? </p>
  
  <p><strong>lambda function:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Net.Http;
  using System.Net.Http.Headers;
  using System.Runtime.Serialization.Formatters.Binary;
  using Amazon.Lambda.Core;
  using Newtonsoft.Json.Linq;
  
  // Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
  [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
  namespace AWSLambda1
  {
      public class Function
      {
          public void PostsBasedOnOddOrEven(string input, ILambdaContext context)
          {
              var details = JObject.Parse(input);
              var postId = (int) details["id"];
              var oddOrEvenResult = (int) details["OddOrEvenPostsResult"];
          }
      }
  }
  </code></pre>
  
  <p><strong>Input to Lambda function from Step Function:</strong></p>
  
  <pre><code>{
    "id": "1",
    "OddOrEvenPostsResult": 2
  }
  </code></pre>
  
  <p><strong>Input to Lambda function (which works through the Visual Studio Invoke):</strong></p>
  
  <pre><code>"{ \"id\": \"1\", \"OddOrEvenPostsResult\": 2}"
  </code></pre>
  
  <p><strong>Exception Stack Trace:</strong></p>
  
  <pre><code>{
    "errorType": "JsonReaderException",
    "errorMessage": "Unexpected character encountered while parsing value: {. Path '', line 1, position 1.",
    "stackTrace": [
      "at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)",
      "at Newtonsoft.Json.JsonTextReader.ReadAsString()",
      "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)",
      "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)",
      "at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)",
      "at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)",
      "at Amazon.Lambda.Serialization.Json.JsonSerializer.Deserialize[T](Stream requestStream)",
      "at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
    ]
  }
  </code></pre>
  
  <p><strong>Lambda Function not working when it is part of Step Function</strong></p>
  
  <p><a href="https://i.stack.imgur.com/7GVEc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7GVEc.jpg" alt="Lambda Function not working when it is part of Step Function"></a></p>
  
  <p><strong>Lambda Function working when tested individually</strong></p>
  
  <p><a href="https://i.stack.imgur.com/1FelY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1FelY.jpg" alt="Lambda Function working when tested individually"></a></p>