{"id":26911694,"url":"https://github.com/culturekings/shopify-json-parser","last_synced_at":"2025-10-14T20:34:28.546Z","repository":{"id":49838541,"uuid":"69790827","full_name":"culturekings/shopify-json-parser","owner":"culturekings","description":"Shopify Liquid snippets to parse a JSON string to local variables - Unsupported April 2021","archived":false,"fork":false,"pushed_at":"2018-04-09T09:43:39.000Z","size":12,"stargazers_count":93,"open_issues_count":7,"forks_count":21,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-01T14:52:27.993Z","etag":null,"topics":["json-parser","liquid","shopify"],"latest_commit_sha":null,"homepage":"","language":"Liquid","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/culturekings.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-02T10:14:05.000Z","updated_at":"2024-11-15T18:36:26.000Z","dependencies_parsed_at":"2022-08-26T00:20:15.323Z","dependency_job_id":null,"html_url":"https://github.com/culturekings/shopify-json-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/culturekings/shopify-json-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/culturekings%2Fshopify-json-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/culturekings%2Fshopify-json-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/culturekings%2Fshopify-json-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/culturekings%2Fshopify-json-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/culturekings","download_url":"https://codeload.github.com/culturekings/shopify-json-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/culturekings%2Fshopify-json-parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020901,"owners_count":26086948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json-parser","liquid","shopify"],"created_at":"2025-04-01T14:49:28.780Z","updated_at":"2025-10-14T20:34:28.531Z","avatar_url":"https://github.com/culturekings.png","language":"Liquid","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shopify Liquid Json Parser / Decoder\n\nAs the name suggests these snippets allow you to be able to use json strings either directly or pulled from metafields inside your Shopify templates.\n\n## Getting Started\n\nThis project is built entirely from liquid which means it is supported on all Shopify stores. Let's hope that one day this library is replaced by native support.\n\n### Installing\n\nInstalling is rather simple. Just copy the two following files in to your snippets directory. The file names are important so keep them the same.\n\n```\njson_decode.liquid - This is the file that does the hardwork\njd__function.liquid - This provides core functions for the json_decode snippet and also provides convenience methods.\njson_decode_output.liquid - This file is optional and just provides another way to access the data\njson_lazy_decode.liquid - This file is optional and provides a more efficient decode for single array values.\n```\n\nAnd your done!\n\n## Usage\n\nOk lets start with an example. Here we are going to store a JSON string in to the `json` variable in our template. This is standard liquid.\n\n```liquid\n{%- capture 'json' -%}\n{\n    \"product\": {\n        \"colour\": \"red\",\n        \"condition\": \"new\",\n        \"body_html\": \"Test\",\n        \"vendor\": \"Apple\",\n\t}\n}\n{%- endcapture -%}\n```\n\nUsually from here you wouldn't be able to do anything with this data except push it out to render on the client side and handle it with JS.\n\nLets now load this string in to the json_decode snippet so that we can then access it later in the liquid file\n\n```liquid\n{%- capture json_error -%}\n    {%- include 'json_decode' jd__namespace:'example' jd__data:json -%}\n{%- endcapture -%}\n```\n\nA quick break down of what the above does\n\n1. We wrap the include in a `capture` as it doesn't actually output anything unless there is an error.\nIf there is an error the `capture ` puts it in a variable rather than exposing it to your store customers.\nThis is optional however it is highly recommended to use this method.\n\n2. We `include` the file `json_decode` from our snippets directory. Along with this we set the top level namespace for our json which is important to be able to handle multiple json files.\nAs we can see this is done by passing the string `example` to the `jd__namespace` include variable. We also then pass our `json` variable we created earlier in to the `jd__data` include variable.\nBoth `jd__namespace` and `jd__data` are required for the snippet to work.\n\nWhat the above does for us is actually build 2 new variables in our liquid template called `jd__global_keys` and `jd__global_values`. It is possible to use these directly however the\nfollowing methods allow you to access the values in a much simplier way.\n\n## Accessing your JSON data.\n\nThere are multiple methods to access your data and we will start with the simpliest approach and that is outputting your data directly in your template.\n\nYour data is accessed by using a simple dot notation syntax.\n\n#### First Method\n\n\nTo access the `body_html` in the json example above we would first use our namespace `example` that was set above in your include statement and then following our nested json object as per below.\n\n`example.product.body_html`\n\nWe can't however use this directly within a variable tag as Liquid doesn't allow assignment of variables dynamically. Instead we use a helper snippet and in this case `json_decode_output`\n\n`{% include 'json_decode_output' with 'example.product.body_html' %}`\n\nWe simply pass the dot syntax to the `with` function of the include statement.\n\n#### Second Method\n\nThe same method can be achieved by using another include snippet. The `jd__function` snippet works by passing a function name and variables in to the `with` part of the include tag.\n\nThe available functions are `echo`, `keys` and `values`. All functions variables are passed by a delimited pipe `|` symbol.\n\n-----\n\n##### ECHO\n\nThe `echo` function works by first adding the `|` symbol and then the variable name you want to access such as below\n\n```liquid\n{% include 'jd__function' with 'echo|example.product.body_html' %}\n```\n\n-----\n\n##### KEYS\n\nThe `keys` function allows you to access the keys of arrays and objects so that you can either iterate over or output the data.\n\nThe syntax for `keys` is `keys|:name|:separator` the `:name` attribute is the name of the Object or Array you want to access. In the above example we could use `example.product` to\naccess an array containing `colour, condition, body_html and vendor` with their full namespaces. The `separator` attribute is optional and if not used will cause the below function to output its\n value to a `jd__yield_1` liquid variable. If the `separator` attribute is used then the array will be outputted directly to the template using the provided seperator between array keys.\n\n```liquid\n{%- include 'jd__function' with 'keys|example.product' -%}{%- assign product_keys = jd__yield_1 -%}\n```\nThe above will set `product_keys` as an array which can then be used in for loops or with array filters.\n\n```liquid\n{%- include 'jd__function' with 'keys|example.product|\u003cbr\u003e' -%}\n```\n\nThis on the other hand will output each of the keys directly and be separated with the defined `\u003cbr\u003e`\n\n-------\n\n##### VALUES\n\nThe `values` function matches the above `keys` function with the only difference being the variables value will be outputted rather than the key name\n\n```liquid\n{%- include 'jd__function' with 'values|example.product' -%}{%- assign product_keys = jd__yield_1 -%}\n```\nThe above will set `product_keys` as an array which can then be used in for loops or with array filters.\n\n```liquid\n{%- include 'jd__function' with 'values|example.product|\u003cbr\u003e' -%}\n```\n\nThis on the other hand will output each of the keys directly and be separated with the defined `\u003cbr\u003e`\n\n##### VALUES\n\nThe `values` function matches the above `keys` function with the only difference being the variables value will be outputted rather than the key name\n\n```liquid\n{%- include 'jd__function' with 'values|example.product' -%}{%- assign product_values = jd__yield_1 -%}\n```\nThe above will set `product_keys` as an array which can then be used in for loops or with array filters.\n\n```liquid\n{%- include 'jd__function' with 'values|example.product|\u003cbr\u003e' -%}\n```\n\nThis on the other hand will output each of the keys directly and be separated with the defined `\u003cbr\u003e`\n\n## Example Usage\n\nLooping over JSON object/array keys\n\n```liquid\n{%- include 'jd__function' with 'keys|example.product' -%}{%- assign product_keys = jd__yield_1 -%}\n{%- for key in product_keys -%}\n{%- assign prepared_function = echo | append: '|' | append: key -%}\n    {{ key }} has a value of {% include 'jd__function' with prepared_function %} \u003cbr\u003e\n    {{ key }} has a value of {% include 'json_decode_output' with key %} \u003cbr\u003e\n{%- endfor -%}\n```\n\nStoring a variable\n\n```liquid\n{%- capture body_html -%}{% include 'jd__function' with 'echo|example.product.body_html' %}{%- endcapture -%}\n```\n\nAccessing Keys and Values\n\n```liquid\n{% include 'json_decode_output' with 'example.product__keys' | split: jd__separator_2 | join: '\u003cbr\u003e'  %}\n{% include 'json_decode_output' with 'example.product__values' | split: jd__separator_2 | join: '\u003cbr\u003e'  %}\n```\n\n## Full Usage\n\n```liquid\n{%- capture 'json' -%}[\"one\",\"two\",\"three\"]{%- endcapture -%}\n{%- capture json_error -%}{%- include 'json_decode' jd__namespace:'count' jd__data:json -%}{%- endcapture -%}\n{%- if json_error != '' -%}{{ json_error }}{%- endif %}\n{%- include 'jd__function' with 'values|count' -%}{%- assign values = jd__yield_1 -%}\nCounting to 3 : {{ values | join: \", \" }}\n```\n\n## Performance Issues and Work Arounds\n\nAs this library is written in liquid its processing speed isn't the greatest. \n\nWe have found when looping over products in a collection can slow the liquid render time to greater than 5 seconds.\n\nTo overcome this we have developed a very simple lazy parser that only looks for a key and responds with the array value.\n\nUsage is as follows\n\n```liquid\n{% include 'json_lazy_decode' json: product.metafields.global.JAN key: 'three_sixty' %}{% assign three_sixty = jld__yield_1 %}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fculturekings%2Fshopify-json-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fculturekings%2Fshopify-json-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fculturekings%2Fshopify-json-parser/lists"}