Home platformOS Logo

Parsing json to hash

Last edit: Mar 05, 2020

November 26, 2018


To make your work with json easier we introduced parse_json tag and renamed to_hash filter to parse_json.

parse_json tag

Using parse_json filter while keeping your json tidy and formatted forced you to use capture.
parse_json tag is basically a hybrid of capture and to_hash, it parses json string inside of the tag and converts it to a hash.

Why would you want to convert your json config to a hash?
To be able to iterate over it, use filters that will modify the structure, traverse the tree.


{% parse_json car %}
    "maker": "Honda",
    "model": "CRX",
    "version": "EE8",
    "power": 180
{% endparse_json %}

Hash: {{ car }}
JSON: {{ car | json }}

{% for property in car -%}
{{ property[0] }}: {{ property[1] }}
{% endfor %}


Hash: {"maker":"Honda","model":"CRX","version":"EE8","power":180}
JSON: {"maker":"Honda","model":"CRX","version":"EE8","power":180}

maker: Honda
model: CRX
version: EE8
power: 180

parse_json filter

Usage of parse_json is exactly the same, as a matter of fact, to keep backwards compatibility, to_hash still works.


{% assign car = '{ "maker": "Honda", "model": "CRX", "version": "EE8", "power": 180 }' %}
{% assign object = car | parse_json %}
Maker: {{ car.maker }}


Maker: Honda


We are always happy to help with any questions you may have.

contact us