Use Cases



Parsley toJSON()

The toJSON() Parsley call allows users to create custom endpoints from Models and Item.

The Parsley method toJSON() enables users to create custom endpoints with a fully hydrated JSON object. It can also be used inline with JavaScript included in Views, providing additional access to a Content Item's stored data.

The toJSON() method has two optional parameters, giving the user control over hydration level and the inclusion of metadata. This is achieved with the following syntax:

  • depth is an integer for hydration depth, max depth is 5
  • showMeta supports a boolean value of true or _false. true _ provides all meta, routing, zuid details, and locale details. false provides only content.

The method's parameters, depth and showMeta, are optional. The default output of the method, without specification, will include meta data and a hydration depth level of 2.

Using the Method

The toJSON() method can be used in a variety of ways to format the desired content and the URL routing location it will be rendered from. Below details how this can be accomplished in three different ways:

  1. Applying the Parsley method to this inside of the Item associated View will access the corresponding Item's content. The Parsley keyword this can only be used on a Content Model generated View, as it points to the connected item. For example: {{this.toJSON(depth, showMeta)}}
  2. Adding the method to the Parsley first() or last() calls can access a corresponding item in a Multi-Entry or Dataset Model. For example: {{model.first().toJSON(2, true)}}
  3. The method can also be used in Pasley each loops to render a JSON object of each item. Inside the each loop, filters can be applied by adding Parsley if or where conditionals as well to only output desired objects. For example:

For examples of the toJSON() method, please visit the Parsley REPL. Additional syntax details can be found in the Parsley Index.

Start Here

We will listen to your needs and walk you through how Zesty can help your team.

Connect with Content Experts

Book a free 15-minute consultation with a content expert. Discuss your application, pain points and requirements. Understand how Zesty's lower total cost of ownership, features, functionality can elevate your business by creating extraordinary digital experiences.

Trusted By

zesty customer logo Sonyzesty customer logo Rocket Leaguezesty customer logo Singlifezesty customer logo Acornszesty customer logo Phoenix Sunszesty customer logo Wattpadzesty customer logo Corner Shopzesty customer logo Bjs


zesty customer logo zesty customer logo zesty customer logo zesty customer logo

Enter your details to connect with a Content Expert

First Name

Last Name


Phone (optional)


Please tell us about your project (optional)