Reputation: 1
I have a json data. I need key and value data from it. My json looks like this.
{
"content": {
"key1": "value1",
"key2": "value2",
}
}
Need to convert to the below format.
{
"Key": "key1",
"Value": "value1"
}
I tried below liquid. I get data as [key1,value1].
{%- for data in content -%}
"Key": {{data[0]}}
"Value": {{data[1]}}
{%- endfor -%}
Upvotes: 0
Views: 1343
Reputation: 382
In Liquid, you can extract key value pairs from a JSON object like the one you provided. But, you can access the keys and values in the JSON object in the following way:
{% assign content = {
"key1": "value1",
"key2": "value2"
} %}
{% for key in content %}
"Key": "{{ key }}",
"Value": "{{ content[key] }}"
{% endfor %}
Upvotes: 1