🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators JsonGetProp
This page was created by Charles on 2024-08-16. Last edited by Wikiadmin on 2026-07-29.

JsonGetProp is an OCL operator for you to read a named property from a JSON string, including properties inside nested JSON objects.

Syntax

jsonString.JsonGetProp('propertyName')
Part Meaning
jsonString The JSON string that contains the property you want to read.
'propertyName' The name of the JSON property to retrieve.

Return value

JsonGetProp returns the value of the requested JSON property as a string.

If the property is unavailable, the operator returns null. Account for this result before using the returned value in later OCL expressions.

Read a top-level property

Use JsonGetProp with the name of a property at the top level of the JSON string.

'{name: "Samuel"}'.JsonGetProp('name')

The expression returns:

'Samuel'

Read a nested property

You can chain JsonGetProp calls when one property contains another JSON object. The first call retrieves the nested object; the next call retrieves a property from that object.

'{person: {name: "Samuel", age: 25}}'.JsonGetProp('person').JsonGetProp('age')

The expression returns the value of age:

25

In this example, JsonGetProp('person') retrieves the person object and JsonGetProp('age') retrieves its age property.

Handle unavailable properties

A property name must be available in the JSON value passed to the operator. For example, this expression returns null because email is not present:

'{name: "Samuel"}'.JsonGetProp('email')

Use with ViewModel JSON

If you need JSON generated from a ViewModel, use ViewModelAsJSon. You can then use JsonGetProp to read a property from the resulting JSON string. Presentation names configured on ViewModel attributes affect the JSON node names generated by ViewModelAsJSon.

See also