Examples

Input: {“username”: “Jonas”, “email”: “jonas@gmail.com”}
Output:

{

“username”: “Jonas”,

“email”: “jonas@gmail.com”

}

Input: {“username”: “Jonas”, “devices”:[“iPhone 13 Pro”, “Samsung Galaxy S30”]}

Output:
{

“username”: “Jonas”,

“devices”:

[

“iPhone 13 Pro”,

“Samsung Galaxy S30”

]

}

Algorithm for JSON Formatter without using external library

Similar Reads

JSON Formatter

Given an input string representing a JSON object, print a string denoting the JSON object with the given format and indentation....

Examples :

Input: {“username”: “Jonas”, “email”: “jonas@gmail.com”}Output: { “username”: “Jonas”, “email”: “jonas@gmail.com” } Input: {“username”: “Jonas”, “devices”:[“iPhone 13 Pro”, “Samsung Galaxy S30”]} Output:{ “username”: “Jonas”, “devices”: [ “iPhone 13 Pro”, “Samsung Galaxy S30” ] }...

Algorithm for JSON Formatter:

The basic idea is to iterate through the input JSON string character by character and keep track of the indentation level to format the output string correctly. Here’s a high-level approach:...