Complex query parsing enables NestJS applications to handle nested objects and arrays in URL query strings, going beyond simple key-value pairs.
Examples
?filter[where][name]=John&filter[where][age]=30
?item[]=1&item[]=2
Configuration
Express
Use the extended query parser:
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.set('query parser', 'extended');Fastify
Configure a custom querystringParser with the qs library:
import { FastifyAdapter } from '@nestjs/platform-fastify';
import qs from 'qs';
const app = await NestFactory.create(
AppModule,
new FastifyAdapter({
querystringParser: (str) => qs.parse(str),
}),
);Installation
For Fastify, install the querystring parser:
npm install qs