// The top-level value can be any JSON type, not only objects or arraysconst jsonString = JSON.stringify('This is an example top-level string')console.log(truncateJson(jsonString, 25).jsonString)// '"This is an example t..."' (25 bytes)
Install
npm install truncate-json
This package works in both Node.js >=18.18.0 and
browsers.