DEV Community

Cover image for Add Quotes to your Unquoted JSON Objects
Omar for ClickPesa

Posted on • Edited on

44

Add Quotes to your Unquoted JSON Objects

In this article, we will not discuss what JSON or Javascript objects are; or their differences in syntax or usage, many articles have already covered them.

One thing to keep in mind is that, according to specification JSON property names must be double-quoted.

// Example: JavaScript Object
{
    id: "TF_CE8TUEPX2LA",
    status: "PENDING",
    failureReason: null,
    language: "en",
    createdAt: 1669797871000,
    updatedAt: 1669797872000,
    completedAt: null,
    depositInitiatedAt: null,
    cancelledAt: null,
    ...
}

// Example: JSON Object
{
    "id": "TF_CE8TUEPX2LA",
    "status": "PENDING",
    "failureReason": null,
    "language": "en",
    "createdAt": 1669797871000,
    "updatedAt": 1669797872000,
    "completedAt": null,
    "depositInitiatedAt": null,
    "cancelledAt": null,
    ...
}
Enter fullscreen mode Exit fullscreen mode

The requirement to convert a JavaScript object into a JSON object frequently arises while developing web applications. Often one needs to utilize a valid JSON object, for instance, when testing an endpoint with a JSON payload over an HTTP client like Postman or Insomnia.

There is no doubt that your IDE allows you to pick numerous keys and add double quotes to the beginning and end of each key, but imagine if you had 200~300 keys! 🤯

Additionally, you could perform the conversion using the JSON.stringify() method, but who wants that? Right?🥱

I'm not sure if you know this, but you can use the Console tool from Google Chrome DevTools to quickly convert Javascript Object to JSON Object.

Here are the steps..

  1. Copy Unquoted JSON Object on clipboard
  2. Navigate to Chrome Console Tab
  3. Paste Unquoted JSON Object on console
  4. Hit Enter
  5. Right-Click on the result object to see options
  6. Use Copy object option to copy your valid JSON Object and go break the internet!

Copy Object on Chrome Console

More tips such as this one that helps you move quickly are shared every month on our Blog. Make sure you take a look at them.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (1)

Collapse
 
bgknockout profile image
bullseye21

thanks bro <3

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay