<p>A subscription's <code>planData</code> is currently only stored as JSON. You can use that JSON in your template but you'll need to decode it first. Marion Newlevant’s <a href="https://github.com/marionnewlevant/craft-twig_perversion/" rel="nofollow noreferrer">Twig Perversion</a> plugin adds a <code>json_decode</code> filter among other helpful capabilities to Twig.</p>

<p>With that plugin installed, set <code>planData</code> to a variable with the <code>json_decode</code> filter applied to it then you can access attributes of <code>planData</code> as you normally would in Twig.</p>

<pre><code>{% set plans = craft.commerce.getPlans().getAllPlans() %}
{% for plan in plans %}
    {% set planData = plan.planData|json_decode %}
    {{ planData.plan.amount }}
    {# Stripe stores the amount as cents, so formatting for dollars or euros might look like this #}
    {{ (planData.plan.amount / 100)|currency }}
    {# Trial period  #}
    {{ planData.plan.trial_period_days }}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2018-10-27T19:27:33.993Z
Doesn't look like `|json_decode` is a native Twig filter. Looks like this plugin adds it though (not sure if it supports Craft 3). https://github.com/diit/Json-Decode-Twig I was hoping there was native support.
Simon Kuran
CC BY-SA 4.0
2018-10-27T22:33:32.253Z
@SimonKuran — You are correct. I thought it was native in Craft 3, but I have Marion Newlevant’s [Twig Perversion](https://github.com/marionnewlevant/craft-twig_perversion/) plugin installed which adds a `json_decode` filter and other helpful capabilities to Twig. Updated my answer with this info.
Stephen Bowling
CC BY-SA 4.0
2019-06-17T20:37:44.807Z
I believe that `json_decode` filter is now native (at least as of Craft 3.1.30)
SoHo
CC BY-SA 4.0
2018-10-27T13:14:06.240Z
2018-10-27T22:33:07.420Z
2018-10-27T22:33:07.420Z
Stephen Bowling
<p>How do I access a subscription plan's planData? Maybe as an object? I'm using Commerce 2 with the Stripe gateway.</p>

<p>For example:</p>

<pre><code>{% set plans = craft.commerce.getPlans().getAllPlans() %}
{% for plan in plans %}
    {{ dump(plan.planData) }}
{% endfor %}
</code></pre>

<p><code>planData</code> looks like JSON stored as a string. How do I access its data (<code>amount</code>, <code>trial_period_days</code> etc.) on the front end?</p>

<p>Does this need to be handled by a custom plugin? Seems like something that should be available out of the box. Hopefully I just over looked it.</p>

<craft3><plugin-craftcommerce2><stripe>
Get Commerce 2's Stripe subscription planData as object
# Get Commerce 2's Stripe subscription planData as object

(Asked by: username_0 on 2018-10-27)

How do I access a subscription plan's planData? Maybe as an object? I'm using Commerce 2 with the Stripe gateway.
For example:
{% set plans = craft.commerce.getPlans().getAllPlans() %}
{% for plan in plans %}
    {{ dump(plan.planData) }}
{% endfor %}

planData looks like JSON stored as a string. How do I access its data (amount, trial_period_days etc.) on the front end?
Does this need to be handled by a custom plugin? Seems like something that should be available out of the box. Hopefully I just over looked it.

**Tags:** craft3, plugin-craftcommerce2, stripe


---

## 1 answers

### Answer by username_1 on 2018-10-27. Score: 3 | Accepted answer

A subscription's planData is currently only stored as JSON. You can use that JSON in your template but you'll need to decode it first. Marion Newlevant’s Twig Perversion plugin adds a json_decode filter among other helpful capabilities to Twig.
With that plugin installed, set planData to a variable with the json_decode filter applied to it then you can access attributes of planData as you normally would in Twig.
{% set plans = craft.commerce.getPlans().getAllPlans() %}
{% for plan in plans %}
    {% set planData = plan.planData|json_decode %}
    {{ planData.plan.amount }}
    {# Stripe stores the amount as cents, so formatting for dollars or euros might look like this #}
    {{ (planData.plan.amount / 100)|currency }}
    {# Trial period  #}
    {{ planData.plan.trial_period_days }}
{% endfor %}

> **Comments:**
> **username_0**: Doesn't look like `|json_decode` is a native Twig filter. Looks like this plugin adds it though (not sure if it supports Craft 3). https://github.com/diit/Json-Decode-Twig I was hoping there was native support.  
> **username_1**: @SimonKuran — You are correct. I thought it was native in Craft 3, but I have Marion Newlevant’s [Twig Perversion](https://github.com/marionnewlevant/craft-twig_perversion/) plugin installed which adds a `json_decode` filter and other helpful capabilities to Twig. Updated my answer with this info.  
> **username_2**: I believe that `json_decode` filter is now native (at least as of Craft 3.1.30)  

---

