skip to Main Content

This is on AWS Eventbridge input transformer, AWS UI not code

So i have a JSON

{
  "version": "0",
  "id": "437e4ed4-8ee1a178",
  "detail-type": "blah",
  "source": "blahblah",
  "account": "011604459942",
  "time": "2023-11-20T23:20:14Z",
  "detail": {
    "transaction_id": 6787,
    "customer_id": 1234,
   ...
    "created_at": "2023-11-21T10:19:40.929+11:00",
    "updated_at": "2023-11-21T10:19:52.425+11:00"
  }
}

and inside that json i have the detail json, i want to reference it with JSONPath to reference but i am failing

Input path

{
  "detail": "$.detail"
}

Template

{  
"document": <detail>
}

result

{
  "document": [object Object]

}

How do i get all the values in detail and not [Object object]? i need to do this cause whats in detail changes per request so i cant list all the values

2

Answers


  1. public void sandbox() {
            String json = "{n" +
                    "  "version": "0",n" +
                    "  "id": "437e4ed4-8ee1a178",n" +
                    "  "detail-type": "blah",n" +
                    "  "source": "blahblah",n" +
                    "  "account": "011604459942",n" +
                    "  "time": "2023-11-20T23:20:14Z",n" +
                    "  "detail": {n" +
                    "    "transaction_id": 6787,n" +
                    "    "customer_id": 1234,n" +
                    "    "created_at": "2023-11-21T10:19:40.929+11:00",n" +
                    "    "updated_at": "2023-11-21T10:19:52.425+11:00"n" +
                    "  }n" +
                    "}";
            Object detail = JsonPath.read(json,"$.detail");
            System.out.println(detail);
        }
    
    • result
    {transaction_id=6787, customer_id=1234, created_at=2023-11-21T10:19:40.929+11:00, updated_at=2023-11-21T10:19:52.425+11:00}
    
    Login or Signup to reply.
  2. You must add all fields you need from detail to the path:

     {
       "transaction_id": "$.detail.transaction_id",
       "customer_id": "$.detail.customer_id",
       "created_at": "$.detail.created_at",
       "updated_at": "$.detail.updated_at"
     }
    

    Also, update your template:

     {  
      "document": "{ "transaction_id": "<transaction_id>", "customer_id": "<customer_id>", "created_at": "<created_at>", "updated_at": "<updated_at>" }"
     }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search