abs-nestjs-json-service
v0.0.4
Published
`JsonService` is a custom json service that can be used in a NestJS to stringify or parse a json data
Downloads
228
Readme
JsonService Documentation
JsonService is a custom json service that can be used in a NestJS to stringify or parse a json data
Installation
To install the necessary dependencies, run:
npm install abs-nestjs-json-serviceUsage with NestJS
- Import the JsonService into your module:
import { Module } from '@nestjs/common';
import { JsonService } from 'abs-nestjs-json-service';
@Module({
providers: [JsonService],
exports: [JsonService],
})
export class AppModule {}- Inject the JsonService into your service or controller:
import { Injectable } from '@nestjs/common';
import { JsonService } from 'abs-nestjs-json-service';
@Injectable()
export class SomeService {
constructor(private readonly json: JsonService) {}
someMethod() {
const data = { message: 'Hello world' };
const jsonRawData = this.json.stringify(data, {
default: 'This is a default value if data is null or empty',
});
const jsonData = this.json.safeParse(jsonRawData);
}
}