import React from "react"; import dynamic from "next/dynamic"; import Head from "next/head"; import styled from "styled-components"; import { Button } from "@mantine/core"; import materialDark from "react-syntax-highlighter/dist/cjs/styles/prism/material-dark"; import { Footer } from "src/components/Footer"; const SyntaxHighlighter = dynamic(() => import("react-syntax-highlighter/dist/cjs/prism-async"), { ssr: false, }); const StyledFrame = styled.iframe` border: none; width: 80%; flex: 500px; margin: 3% auto; `; const StyledPage = styled.div` padding: 5%; `; const StyledContent = styled.section` margin-top: 20px; background: rgba(181, 116, 214, 0.23); padding: 16px; border-radius: 6px; `; const StyledDescription = styled.div``; const StyledContentBody = styled.div` display: flex; flex-direction: column; flex-wrap: wrap; gap: 15px; line-height: 1.8; ${StyledDescription} { flex: 1; } `; const StyledHighlight = styled.span<{ link?: boolean; alert?: boolean }>` text-align: left; white-space: nowrap; color: ${({ theme, link, alert }) => alert ? theme.DANGER : link ? theme.BLURPLE : theme.TEXT_POSITIVE}; background: ${({ theme }) => theme.BACKGROUND_TERTIARY}; border-radius: 4px; font-weight: 500; padding: 4px; font-size: 14px; margin: ${({ alert }) => alert && "8px 0"}; `; const Docs = () => { return ( <> Creating JSON Crack Embed | JSON Crack

Documentation

# Fetching from URL

By adding ?json=https://catfact.ninja/fact query at the end of iframe src you will be able to fetch from URL at widgets without additional scripts. This applies to editor page as well, the following link will fetch the url at the editor:{" "} https://jsoncrack.com/editor?json=https://catfact.ninja/fact See the Pen Untitled by Aykut Saraç (@AykutSarac) on{" "} CodePen.

# Embed Saved JSON

Just like fetching from URL above, you can embed saved public json by adding the json id to "json" query{" "} ?json=639b65c5a82efc29a24b2de2 See the Pen Untitled by Aykut Saraç (@AykutSarac) on{" "} CodePen.

# Communicating with API

◼︎ Post Message to Embed

Communicating with the embed is possible with{" "} MessagePort , you should pass an object consist of "json" and "options" key where json is a string and options is an object that may contain the following: {`{\n\ttheme: "light" | "dark",\n\tdirection: "TOP" | "RIGHT" | "DOWN" | "LEFT"\n}`} See the Pen Untitled by Aykut Saraç (@AykutSarac) on{" "} CodePen.

◼︎ On Page Load

⚠️ Important! - iframe should be defined before the script tag ⚠️ Note - postMessage should be delayed using setTimeout To display JSON on load event, you should post json into iframe using it's onload event like in the example. Make sure to use{" "} setTimeout when loading data and set a time around 500ms otherwise it won't work. See the Pen Untitled by Aykut Saraç (@AykutSarac) on{" "} CodePen.