---
name: "up.element.jsonAttr"
area: "API"
kind: "JavaScript function"
parent: "up.element module"
url: "https://unpoly.com/api/up.element.jsonAttr"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.element module](https://unpoly.com/api/up.element.md)</nav>

# up.element.jsonAttr(element, attribute)

Reads the given attribute from the element, parsed as [relaxed JSON](https://unpoly.com/api/relaxed-json.md).

Returns `undefined` if the attribute value is [blank](https://unpoly.com/api/up.util.isBlank.md) or only consists of whitespace.

Throws a `SyntaxError` if the attribute value is an invalid JSON string.

---

## Parameters {#parameters}

### element {#element}

(required)

The element from which to retrieve the attribute value.

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)

### attribute {#attribute}

(required)

The attribute name.

Type: string

---

## Return value {#return-value}

The cast attribute value.

Type: [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects) | undefined

