ParseBoolPipe

Parses a string or boolean value into a strict boolean.

Since NestJS 10/11 Spec ↗

Syntax

new ParseBoolPipe(options?: { errorHttpStatusCode })

Parameters

NameTypeRequiredDescription
options object No Optional errorHttpStatusCode and custom exceptionFactory.

Returns

boolean — true for "true"/true, false for "false"/false.

Throws

  • BadRequestException — Thrown when the value is not a recognized boolean.

Examples

import { Controller, Get, Query, ParseBoolPipe } from '@nestjs/common';

@Controller('cats')
export class CatsController {
  @Get()
  find(@Query('active', ParseBoolPipe) active: boolean) {
    return { active };
  }
}

Notes

Only the strings "true" and "false" (and actual booleans) are accepted. Combine with DefaultValuePipe for optional flags so missing values do not raise an error.