How can I list all properties of an object in JavaScript?

Topic summary

Goal: List all properties of an object, focusing on Shopify Liquid (templating language), not vanilla JavaScript.

Suggested approach:

  • Consult Shopify Liquid docs for built-in object structure.
  • Use the “to json” filter to output most object keys and values for inspection.

Key limitations noted:

  • The JSON filter omits some properties (example given: inventory details on variants). Those properties may still exist on the Liquid object in templates but won’t appear in the JSON output; documentation is required to identify them.
  • The JSON filter doesn’t work on all objects (e.g., it won’t work on the section object).

Latest update/issue:

  • A participant specifically needs “inventory details on variants,” aiming to show inventory quantities by location. They can list locations where a variant is available but cannot access per-location inventory counts.

Status:

  • No confirmed method provided to retrieve variant inventory quantities per location via Liquid or the JSON filter. The discussion remains unresolved, with open questions about accessing those specific inventory details.
Summarized with AI on December 17. AI used: gpt-5.

I’m trying to write a loop that will list the properties of an object. Not necessarily the values of the properties, just a list of the properties a particular object has.

Does anyone know how to do that?

2 Likes

It’d be great if there was a consistent way to iterate over an object, but as it stands the most complete information is in the Shopify liquid docs if you’re looking at built in objects.

The next best option is to use the “to json” filter. For example:


This will give you most object keys (and values). However:

  • The json filter will exclude a few things (from memory the inventory details on variants are one example). However these properties are still available on the liquid object within your templates, they just get excluded in the json filter’s output. You’ll need to refer to the docs for the full picture.
  • The json filter is available on most objects, but not all. For example, it won’t work on {{ section }}.

Hope that helps!

Andrew.

Unfortunate for me, I am precisely looking for “inventory details on variants”.

Working on a pet project, trying to see if It is somehow possible to display inventory quantities of each location. I could print all the locations where a variant is available, but the count is apparently not accessible.