Query Transformation
HTTP query parameters commonly reach NestJS controllers as strings. QueryTransformPipe turns those query objects into predictable JavaScript values before controller code receives them.
Pipeline
QueryTransformPipe performs one check and then delegates the parsing work:
if (metadata.type === 'query' && typeof value === 'object') {
return parseObject(value);
}This keeps transformation scoped to query parameters. Route params, body values, and custom metadata types are returned unchanged.
Parsing Rules
parseObject applies these rules recursively:
| Input | Output |
|---|---|
'42' | 42 |
'3.14' | 3.14 |
'true' | true |
'false' | false |
'null' | null |
['1', '2'] | [1, 2] |
{ 'user.name': 'Ada' } | { user: { name: 'Ada' } } |
Dotted Keys
Dotted keys are expanded into nested objects:
parseObject({
'where.profile.name': 'Ada',
'where.active': 'true',
});
// {
// where: {
// profile: { name: 'Ada' },
// active: true
// }
// }Key collisions
If the same object path is provided in multiple shapes, the final result follows normal object assignment semantics. Avoid sending both dotted and nested variants for the same path.
Boolean Values
The parser recognizes the strings 'true' and 'false' as boolean-like values. When parsing through the internal boolean parser, 'on' and 'yes' also evaluate to true.
Values that are not recognized as boolean-like continue through the other parsing rules.
Numbers
Numeric strings are converted with Number(value).
parseObject({ page: '1', ratio: '0.25' });
// { page: 1, ratio: 0.25 }Empty strings are preserved and are not converted to 0.
JSON Values
Valid JSON object and array strings are parsed recursively.
parseObject({ orderBy: '{"createdAt":"desc"}', ids: '["1","2"]' });
// { orderBy: { createdAt: 'desc' }, ids: [1, 2] }Invalid JSON-like strings are returned unchanged.
Validation
The pipe normalizes values; it does not validate them. For request validation, compose it with Nest's validation pipe and DTO classes.