Javascript example: to and from JSON string

Example converting to and from JSON string using Javascript

This example starts with a plain JavaScript object, converts it to a formatted JSON string with JSON.stringify, and then parses it back with JSON.parse. It demonstrates how serialized JSON preserves values and uses a simple assertion to verify that the parsed object matches the original data.

Result

Console output