Skip to content

Output Transformation

In many cases, the output of your HTTP API data sources may be large and verbose, containing unnecessary data or fields that are not needed. While AI models can handle large amounts of data, it is often beneficial to transform the output to only include the data that is needed, reducing the amount of input tokens that needs to be processed by the model. Infragate allows you to transform the output of your HTTP API data sources using a JMESPath expression.

JMESPath is a query/transformation language for JSON. It allows you to select and transform data from a JSON object.

Consider the following JSON object which comes from a GitLab API call which returns a list of merge request comments. As you can see, it contains a lot of data that is not needed for the purpose of this example.

[{
"id": 2854000374,
"type": "DiffNote",
"body": "Replace \" Test\" with \" World\" instead.",
"author": {
"id": 1001,
"username": "user1",
"public_email": "",
"name": "John Doe",
"state": "active",
"locked": false,
"avatar_url": "https://example.com/uploads/user1/avatar.png",
"web_url": "https://example.com/user1"
},
"created_at": "2025-10-29T17:15:41.258Z",
"updated_at": "2025-10-29T17:15:41.258Z",
"system": false,
"noteable_id": 427528639,
"noteable_type": "MergeRequest",
"project_id": 75691292,
"commit_id": null,
"position": {
"base_sha": "dc246b8a299056d171bf5d72fc05cb1a5b0a4408",
"start_sha": "dc246b8a299056d171bf5d72fc05cb1a5b0a4408",
"head_sha": "06785a540d55460299939f3511ae77385f36d888",
"old_path": "main.go",
"new_path": "main.go",
"position_type": "text",
"old_line": null,
"new_line": 14,
"line_range": {
"start": {
"line_code": "0607f785dfa3c3861b3239f6723eb276d8056461_15_14",
"type": "new",
"old_line": null,
"new_line": 14
},
"end": {
"line_code": "0607f785dfa3c3861b3239f6723eb276d8056461_15_14",
"type": "new",
"old_line": null,
"new_line": 14
}
}
},
"resolvable": true,
"resolved": false,
"resolved_by": null,
"resolved_at": null,
"suggestions": [],
"confidential": false,
"internal": false,
"imported": false,
"imported_from": "none",
"noteable_iid": 1,
"commands_changes": {}
}]

You can use a JMESPath expression to transform the output to only include the data that is needed.

[].{
"comment": body,
"author": author.name,
"commentedOn": {
"fromLine": [position.line_range.start.old_line, position.line_range.start.new_line] | [] | [0],
"toLine": [position.line_range.end.old_line, position.line_range.end.new_line] | [] | [0],
"file": [position.old_path, position.new_path] | [] | [0]
}
}

This expression simply returns the comment body, the author name, and the file and line range that the comment is on. Much cleaner and more concise than the original output.

The transformed output would look like this:

[{
"comment": "Replace \" Test\" with \" World\" instead.",
"author": "John Doe",
"commentedOn": {
"fromLine": 14,
"toLine": 14,
"file": "main.go"
}
}]