Creating a JSON Query

You can view and define Create Lists queries using JavaScript Object Notation (JSON), a text format used to transmit data objects consisting of name/value pairs. When you build a query in the Enhanced or Classic query builder, click the JSON option button to view the JSON representation of your query. Alternatively, you can build a JSON query directly in the editor or click Load JSON to load a JSON text file. When you build a JSON query in the editor, you can save the query to your local machine as a plain text file.

The JSON editor is not intended for use by Limited Users. The record types drop-down list and range entry fields remain locked for this role.

Refer to the JSON.org website for fundamental information about JSON. The following sections provide an introduction to JSON queries in Create Lists:

Create Lists Query Structure

A Create Lists query can be one of two types:

A simple query consists of a target that defines where to find the data and an expression that evaluates to true or false when supplied with data.

JSON Representation

The JSON representation of a Create Lists query consists of one or more query objects that contain one or more expressions.

A Simple Query

The JSON representation of a simple query is a JSON object with target and expr properties representing the query's target and expression, respectively. A simple query contains one complete Create Lists search term ("Bibliographic Title equal to "birds of america"). See Example 1 below to view the JSON representation of a simple query.

A Compound Query

The JSON representation of a compound query is a JSON object with a single queries property for which the value is an array of one or more JSON objects joined by a literal string AND or OR. Each JSON object in the queries array is a representation of a query, which can itself be simple or compound. See Example 2 below to view the JSON representation of a compound query. Note the use and placement of the queries operator on the second line of the compound query.

Target

Within a simple query, the target property has a record property identifying the target record type, and an additional property representing one of the following discriminators used to determine the record field being searched:

See Create Lists JSON Syntax for Record Field Discriminators for a complete list of the JSON Create Lists field discriminators.

The record property in a target has a type property, which in most cases is the name of the record type in lowercase. See Create Lists JSON Syntax for Record-Type Names for a complete list of the JSON syntax for record-type names.

The type property also might have relationType and relationTag properties, if the record type is a soft-linked record type, such as related resource records for orders. See Example 4 below to view the JSON representation of a soft-linked record.

Expression

The JSON representation of a simple expression is a JSON object with an op property and an operands property. The op property is the name of the expression's operator. See Create Lists JSON Syntax for Relational Operators for a complete list of the JSON syntax for valid Create Lists operators. Note that if you use the In operator, you cannot view or edit queries in the Classic editor.

The operands property is an array of JSON strings representing the operands for the expression. An operand specifies the specific data being searched. For example, "birds of america" would be the operand for a simple query that searches for the bibliographic title "Birds of America".

The JSON representation of a compound expression is an array of simple expressions connected with Boolean AND or OR operators.

Examples

The following examples illustrate basic patterns for representing Create Lists queries in JSON.

To learn the element structure, attribute name, or identifying value for any valid Create Lists data, you can use the Classic or Enhanced query builder to specify the data, and then switch to the JSON editor to view the corresponding code.

Example 1: A simple query with a single, simple expression

Example 2: A compound query consisting of two simple queries

Example 3: A simple query with a compound expression

Example 4: A soft-linked record type

Example 5: A compound query illustrating syntax for variable-length, fixed-length, and special fields

Example 6: A query targeting data stored in a barcode field