
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
astro-json-element
Advanced tools
Create/define HTML elements using JSON objects
This component was originaly created to customize an element using props for my pagination component
Note: Using thestyle attribute or tailwindcss classes allows you to style your astro-json-element easier and keep the html and css together
Install package:
npm i astro-json-element
Create Element:
---
import { Element } from 'astro-json-element';
const my_element = {
tag: "h1",
text: "Heading",
class: "heading",
id: "my-heading";
}
---
<Element {...my_element}/>
// <h1 id="my-heading" class="heading">Heading</h1>
---
import { Element } from 'astro-json-element';
const header = {
tag: "header",
style: "font-family:Arial;display:flex;justify-content:space-around;margin:1rem;border-radius:5px;background-color:white;border:3px solid purple",
_heading: {
tag: "h1",
text: "Purple",
style: "font-weight:bold;font-size:3rem;color:purple;"
},
_ul: {
tag: "ul",
style: "display:flex;align-items:center;gap:1rem;font-weight:bold;font-size:1.25rem;color:purple;",
_item1: {
tag: "li",
_link: {
tag: "a",
text: "Home"
}
},
_item2: {
tag: "li",
_link: {
tag: "a",
text: "Products"
}
},
_item3: {
tag: "li",
_link: {
tag: "a",
text: "About"
}
},
_item4: {
tag: "li",
style: "padding:.75rem 1rem;border-radius:5px;background-color:purple;color:white;",
_link: {
tag: "a",
text: "Contact"
}
},
}
}
---
<Element {...header}/>
firstfirsttextbeforeslot (default)afterinnerHTMLlastlastDefault: Elements are slot in at the center of the render order (5 of 9)
firstFirst element in Render Order
lastLast elemenet in Render Order
tagType: string
Default: div
Defines what HTML tag the element will be
slotType: string
Options: first, before, after, last
Default: last
Controls where a _child element will be rendered inside of a parent json-element
textType: string
Set the text of an element, automatically escaped
innerHTMLType: string
Set the innerHTML of an element, a string of HTML
defaultsType: object
Define default props for _child elements
debugType: boolean
Default: false
If true the element will print its props to the console
...attrsType: object
Any other key/value pairs will be added as attributes to your element
---
const my_element = {
tag: "span",
text: "Text",
id: "my-element",
key: value,
}
---
<Element {...my_element}/>
// <span id="my-element" key="value">Text</span>
classType: set | object | array | string
Class uses the class:list directive:
---
const my_element = {
tag: "div",
'class-list': ['This', 'is', 'a', 'test']
}
---
<Element {...my_element}/>
// <div class="This is a test">Text</div>
_[child]Type: astro-json-element
astro-json-elements are recursive, you can create elements inside of elements by prefixing a key with _
NOTE: Some tags like h1-6 and p tags do not allow children and will slot the child element after the defined element inside the parent element
Example:
---
const header = {
tag: "header",
style: "display:flex;justify-content:center;background-color:white;border:3px solid purple",
_heading: {
tag: "h1",
text: "Purple Heading",
style: "font-weight:bold;font-size:3rem;color:purple;"
}
}
---
<Element {...header}/>
Elements are recursive allowing for unlimited nested child Elements
---
const list = {
tag: "ul",
style: "display:flex;align-items:center;gap:1rem;font-weight:bold;font-size:1.25rem;color:purple;",
_item1: {
tag: "li",
_link: {
tag: "a",
text: "Home"
}
},
_item2: {
tag: "li",
_link: {
tag: "a",
text: "Products"
}
},
_item3: {
tag: "li",
_link: {
tag: "a",
text: "About"
}
},
_item4: {
tag: "li",
style: "padding:.75rem 1rem;border-radius:5px;background-color:purple;color:white;",
_link: {
tag: "a",
text: "Contact"
}
},
}
---
<Element {...list}/>
FAQs
Create/define HTML elements using JSON objects
We found that astro-json-element demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.