getting linklist json in shopify through liquid
{% layout none %}
{
"parent":[
{% for link in linklists.main-menu.links %}
{% if link.type == 'collection_link' %}
{% assign parentObj = link | map: 'object' %}
{% assign parentId = parentObj[0].id %}
{"id":"{{ parentId }}", "title":"{{ link.title }}", "handle":"{{ link.handle }}"}
{% else %}
{}
{% endif %}
{% if forloop.last == false %},{% endif %}
{% endfor %}
],
"child":[
{% for link in linklists.main-menu.links %}
{% if link.type != 'collection_link' %}
{% continue %}
{% endif %}
{% assign parentObj = link | map: 'object' %}
{% assign parentId = parentObj[0].id %}
{% for child in link.links %}
{% assign childObj = child | map: 'object' %}
{"id":"{{ childObj[0].id }}", "parent_id":"{{ parentId }}", "title":"{{ child.title }}", "handle":"{{ child.handle }}"}
{% if forloop.last == false %},{% endif %}
{% endfor %}
{% if link.links != blank %}
{% if forloop.first == true %},{% endif %}
{% endif %}
{% endfor %}
],
"sub_child":[
{% for link in linklists.main-menu.links %}
{% if link.type != 'collection_link' %}
{% continue %}
{% endif %}
{% for child in link.links %}
{% assign childObj = child | map: 'object' %}
{% assign childId = childObj[0].id %}
{% for subChild in child.links %}
{% assign subChildObj = subChild | map: 'object' %}
{"id":"{{ subChildObj[0].id }}", "parent_id":"{{ childId }}", "title":"{{ subChild.title }}", "handle":"{{ subChild.handle }}"}
{% if forloop.last == false %},{% endif %}
{% endfor %}
{% if forloop.last == false %},{% endif %}
{% endfor %}
{% endfor %}
]
}