json

The json method logs a JSON object inside a styled card in the terminal. It automatically formats the object with JSON.stringify and wraps it in a card component with configurable width and card options.

Signature

betterConsole.json(obj: any, width?: CardWidth, CardOptions?: CardOptions): void

Parameters

  • obj: The object to be serialized and displayed as formatted JSON.
  • width: An optional CardWidth value — a number, a ratio string ("1/2", "1/3", "2/3", "full"), or "auto". Defaults to "auto".
  • CardOptions: An optional CardOptions object to customize the card's appearance. Defaults to a gray italic border style.

Usage

import betterConsole from "ts-better-console";

// Log a simple object
betterConsole.json({ name: "Alice", age: 30 });

Want to support this project?

If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.

Want to contribute to this project?

Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!