DEV Community

Cover image for How to a add link to JSON?
Hardique Dasore
Hardique Dasore

Posted on

6

How to a add link to JSON?

In another edition to the JSON series, we can also add clickable links are part of the paragraph in the JSON. We can encapsulate the link in the anchor tag <a href='#'></a>. We can add the redirection link in the href so that the user can redirect to the link on click. This hack helps us in avoiding the creation of a separate variable just for the links.



<!DOCTYPE html>
<html>
<body>
<h2>JSON with clickable link</h2>
<span id="heading"></span><br/>
<span id="paragraph"></span>
<script>
const faq= {
 heading: "<b>Heading 1</b>", 
 paragraph: "This is a link to <a href='https://www.google.com'>Google</a>" 
 } 
document.getElementById("heading").innerHTML = faq.heading;
document.getElementById("paragraph").innerHTML = faq.paragraph;
</script>
</body>
</html>


Enter fullscreen mode Exit fullscreen mode

Note: Make sure you use single inverted commas for the link otherwise the JSON will become invalid if we use double inverted commas inside double inverted commas.

The DOM identifies the HTML element in the JSON and converts the text encapsulated to the link. This will help you code your FAQs page better.

Happy Coding!

Follow us on Instagram

Image description

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry 🕒

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay