Skip to content
On this page

๐Ÿ—๏ธ @bridge/json5

Module that gives access to json parsing with the json5 npm package. View Source Code

import { ... } from '@bridge/json5'

โšก Functions


The parse function parses a string that is in JSON format to a JavaScript object. This can be benefical over using the default JSON.parse since this parses the json5 format which means features like comments and trailing commas will not throw errors.

  • Signature: parse(str: string)
  • Returns: any
const jsonStr = '{ "example": "Example Value" }'

const parsedJSON = parse(jsonStr)


The stringify function converts a JavaScript object to a JSON string with the specified formatting.

  • Signature: stringify(obj: any, replacer?: ((this: any, key: string, value: any) => any), space?: space?: string | number)
  • Returns: string
const jsonObj = {
	example: 'ExampleValue',

const convertedJson = stringify(jsonObj)
// When you have converted an object to a string, it can be written to a file for example
await writeFile('./test.json', convertedJson)

Released under the GPL-3.0 License.