Skip to main content

JSONStringify

Applies JSON.stringify to any value:

import { jsonStringify } from 'dynamodb-toolbox/transformers/jsonStringify'

const stringifiedSchema = any().transform(jsonStringify())

If needed, you can provide custom space, replacer and reviver options:

import { jsonStringify } from 'dynamodb-toolbox/transformers/jsonStringify'

const stringifiedSchema = any().transform(
jsonStringify({
space: 2,
// Save prices as cents
replacer: (_, dollars) =>
typeof dollars === 'number'
? Math.round(dollars * 100)
: value,
// Revive cents as dollars
reviver: (_, cents) =>
typeof cents === 'number' ? cents / 100 : cents
})
)