Skip to content

Operators

Nat Van Gulck edited this page Jun 15, 2025 · 20 revisions

JSONLogic operators

For a list of built-in JSONLogic operators see https://jsonlogic.com/operations.html.

PBI Inspector operators

PBI Inspector adds additional operators beyond those provided by the JSONLogic library. Here they are in alphabetical order with associated examples.

count

Counts the number of items in an array.

Example:

    {
      "id": "CHECK_FOR_LOCAL_MEASURES",
      "name": "Check for locally defined measures",
      "description": "Returns an array of report-level measure definitions",
      "part": "ReportExtensions",
      "test": [
        {
          "filter": [
            {
              "var": "entities"
            },
            {
              ">": [
                {
                  "count": [
                    {
                      "var": "measures"
                    }
                  ]
                },
                0
              ]
            }
          ]
        },
        {
          "entities": "/entities"
        },
        []
      ]
    }

diff

Venn diagram

Accepts two JSON array parameters, treats them as non-ordered sets, and returns a JSON array representing the set difference between the first and the second parameter.

Example:

{
  "id": "REMOVE_UNUSED_CUSTOM_VISUALS",
  "name": "Remove custom visuals which are not used in the report.",
  "description": "Returns an array of custom visual names to be removed if any. To disable this rule, mark it as disabled in the base rules file.",
  "disabled": false,
  "part": "Report",
  "test": [
    {
      "diff": [
        {
          "var": "customvis"
        },
        {
          "map": [
            { "part": "Visuals" },
            { "var": "visual.visualType" }
          ]
        }
      ]
    },
    {
      "customvis": "/publicCustomVisuals"
    },
    []
  ]
}

drillvar

Accepts a json pointer string and parses stringified JSON on the right of a '>' character. The drillvar operator was needed in V1 of PBI Inspector due to the large amount the escaped json in the report.json file. It is less relevant for PBI Inspector V2 but still useful for querying escaped json such as in the Deneb custom visual definition.

equalsets

Accepts two JSON array parameters, treats them as non-ordered sets, and determines if they are equal.

filesize

PBI Inspector natively uses JSONLogic to query Fabric CI/CD items' json file contents, however the Fabric items' definition can also include other files such as image files within a Report's StaticResources folder for example. The filesize operator accepts either a file path string as parameter or the output of a partinfo operator and returns the file size in bytes as shown in this example:

{
            "id": "PQ_FILESIZE_CHECK",
            "name": "Check PowerQuery file size.",
            "itemtype": "Dataflow",
            "part": ".pq$",
            "test": [
                {
                    "filesize": [
                        {
                            "partinfo": ""
                        }
                    ]
                },
                0
            ]
        }

filetextsearchcount

The filetetextsearchcount operator takes two parameters, the first being either a file path or the output of the "partinfo" command and the second being a regular expression pattern. The output is the number of regular expression matches.

{
            "id": "SEARCH_SQLDATABASE_FILES",
            "name": "SEARCH_SQLDATABASE_FILES",
            "itemtype": "SQLDatabase",
            "part": ".sql",
            "test": [
                {
                    "filetextsearchcount": [
                        {
                            "partinfo": ""
                        },
                        "ErrorLogID"
                    ]
                },
                0
            ]
        }

intersection

Venn diagram

Accepts two JSON array parameters, treats them as non-ordered sets, and returns a JSON array representing the intersection of both sets.

part

The part operator returns the file content of a Fabric CI/CD item. Currently it's possible to reference PBIR report parts using the following reserved part names (note that the part names are case-sensitive):

  • Report: returns the part with the report.json file path
  • ReportExtensions: returns the part with the "reportExtensions.json" file path
  • Version: returns the part with the version.json file path
  • PagesHeader: returns the part with the pages.json file path depending on the parent part context
  • Pages: returns a list of all parts with *.page.json file paths
  • AllVisuals: returns a list of all parts with *.visual.json file paths
  • Visuals: returns a list of parts with *.visual.json file paths in the context of the rule's own "part" iterator.
  • AllMobileVisuals: returns a list of all parts with *.mobile.json file paths regardless of parent context
  • MobileVisuals: returns a list of parts with *.mobile.json file paths in the context of the rule's own "part" iterator.
  • BookmarksHeader: returns the part with the bookmarks.json file path depending on the parent part context
  • AllBookmarks: returns a list of all parts with *.bookmark.json file paths.
  • Bookmarks: returns a list of parts with *.bookmark.json file paths in the context of the rule's own "part" iterator.
  • Files: returns a list of parts for each file within the parent part context

See below for an example using the "Visuals" part operator within the rule's test definition. The part operator in this example returns visual definitions for each page as an array.

{
  "id": "DISABLE_DROP_SHADOWS_ON_VISUALS",
  "name": "Disable drop shadows on visuals",
  "description": "Drop shadows are not suitable for everyone, this rule returns an array of visuals with drop shadows enabled.",
  "part": "Pages",
  "test": [
    {
      "map": [
        {
          "filter": [
            {
              "part": "Visuals"
            },
            {
              "some": [
                {
                  "var": "visual.visualContainerObjects.dropShadow"
                },
                {
                  "==": [
                    { "var": "properties.show.expr.Literal.Value" },
                    "true"
                  ]
                }
              ]
            }
          ]
        },
        {
          "var": "name"
        }
      ]
    },
    {},
    []
  ]
}

part matching by file name

If the part operator is used to return a part that is not included in the list above (such as for other Fabric CI/CD item) then the part operator will attempt to match the file by name by using a Regular Expression pattern. For example, returning a theme file part might look like this: "part":"CY23SU04.json". Here's another example that returns the contents of CopyJobs json files:

{
            "id": "COPYJOB_JSON_PART",
            "name": "COPYJOB_JSON_PART",
            "itemtype": "CopyJob",
            "test": [
                {
                    "part": ".json$"
                },
                []
            ]
        }

If the part operator's parameter is an empty string then it will be set to the current part iteration as defined by the outer part definition at the rule-level, for example:

{
            "id": "COPYJOB_JSON_PART",
            "name": "COPYJOB_JSON_PART",
            "itemtype": "CopyJob",
            "part": ".json$",
            "test": [
                {
                    "part": ""
                },
                []
            ]
        }

partinfo

The partinfo operator is similar to the part operator except that it returns metadata about the part instead of its content. The following example metadata is returned for each part in JSON format (filesize is returned in bytes):

Folder metadata example:

 { "filesystemname": "root", "filesystempath": "C:\\...\\dw1.Warehouse", "partfilesystemtype": "Folder", "filesize": 49335, "filecount": 12 },

File metadata example:

{ "filesystemname": "Date.sql", "filesystempath": "C:\\...\\dw1.Warehouse\\dbo\\Tables\\Date.sql", "partfilesystemtype": "File", "filesize": 1030, "filecount": 1 }

path

The path operator provides the ability to define a JSONPath to query the context json. PBI Inspector V2 uses the JsonPath.Net implementation. For details about JSONPath syntax with examples see https://docs.json-everything.net/path/basics/ and https://www.rfc-editor.org/rfc/rfc9535.html.

Example:

    {
      "id": "REDUCE_OBJECTS_WITHIN_VISUALS",
      "name": "Reduce the number of objects within visuals",
      "part": "Pages",
      "test": [
        {
          "map": [
            {
              "filter": [
                {
                  "part": "Visuals"
                },
                {
                  ">": [
                    {
                      "count": [
                        {
                          "path": "$..projections[*]"
                        }
                      ]
                    },
                    6
                  ]
                }
              ]
            },
            {
              "var": "name"
            }
          ]
        },
        {},
        []
      ]
    }

query

Accepts a Json node object and operator to apply to the Json node as a second parameter. The following example queries the "version" attribute of the Report's Version JSON file and tests if it equals to "2.0.0".

{
  "id": "CHECK_VERSION",
  "name": "Check version",
  "itemtype": "Report",
  "test": [
    {
      "query": [
        {
          "part": "Version"
        },
        {
          "var": "version"
        }
      ]
    },
    "2.0.0"
  ]
}

rectoverlap

Accepts a JSON array of rectangle ids, x and y coordinates and width, height and optional margin width records. Returns an array of overlapping rectangle ids (inflated by the specified margin width).

{
  "id": "CHECK_FOR_VISUALS_OVERLAP",
  "name": "Check for visuals overlap with a 5px margin",
  "description": "Returns names of visuals that overlap while inflating visuals rectangle area by 5px left, right, top and bottom. Currently this does not check for overlap with the sides of report page itself. This rule does not currently work with visual groups.",
  "disabled": false,
  "part": "Pages",
  "test": [
    {
      "rectoverlap": [
        {
          "map": [
            {
              "filter": [
                {
                  "part": "Visuals"
                },
                {
                  "and": [
                    { "!!": [ { "var": "name" } ] },
                    {
                      "!": [
                        {
                          "in": [
                            {
                              "var": "visual.visualType"
                            },
                            [
                              "card",
                              "slicer",
                              "actionButton"
                            ]
                          ]
                        }
                      ]
                    },
                    {
                      ">=": [
                        { "var": "position.x" },
                        0
                      ]
                    },
                    {
                      ">=": [
                        { "var": "position.y" },
                        0
                      ]
                    },
                    {
                      ">=": [
                        { "var": "position.width" },
                        0
                      ]
                    },
                    {
                      ">=": [
                        { "var": "position.height" },
                        0
                      ]
                    },
                    {
                      "!": [
                        {
                          "var": "isHidden"
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "torecord": [
                "name",
                {
                  "var": "name"
                },
                "x",
                {
                  "var": "position.x"
                },
                "y",
                {
                  "var": "position.y"
                },
                "width",
                {
                  "var": "position.width"
                },
                "height",
                {
                  "var": "position.height"
                }
              ]
            }
          ]
        },
        5
      ]
    },
    []
  ]
}

strcontains

Accepts a search string and regular expression as parameters. Returns the count of regular expression matches in the search string.

{
  "id": "GIVE_VISIBLE_PAGES_MEANINGFUL_NAMES",
  "name": "Give visible pages meaningful names",
  "description": "Returns an array of visible page names with a default 'Page x' display name.",
  "test": [
    {
      "map": [
        {
          "filter": [
            {
              "part": "Pages"
            },
            {
              "and": [
                {
                  "strcontains": [
                    {
                      "var": "displayName"
                    },
                    "^Page [1-9]+$"
                  ]
                },
                {
                  "!=": [
                    {
                      "var": "visibility"
                    },
                    "HiddenInViewMode"
                  ]
                }
              ]
            }
          ]
        },
        {
          "var": "displayName"
        }
      ]
    },
    {},
    []
  ]
}

symdiff

Venn diagram

Accepts two JSON array parameters, treats them as non-ordered sets, and returns a JSON array representing the symmetric difference of both sets.

torecord

Accepts an array of key/value pairs as parameter. Return a JSON record. The following example shows how to compare JSON records such as multiple report setting values.

    {
      "id": "LOCAL_REPORT_SETTINGS",
      "name": "Local report settings",
      "part": "Report",
      "test": [
        {
          "torecord": [
            "isPersistentUserStateDisabled",
            {
              "var": "/settings/isPersistentUserStateDisabled"
            },
            "hideVisualContainerHeader",
            {
              "var": "/settings/hideVisualContainerHeader"
            },
            "useStylableVisualContainerHeader",
            {
              "var": "/settings/useStylableVisualContainerHeader"
            }
          ]
        },
        {
          "isPersistentUserStateDisabled": false,
          "hideVisualContainerHeader": true,
          "useStylableVisualContainerHeader": true
        }
      ]
    }

tostring

Accepts a JSON node as parameter and returns the equivalent stringified JSON.

union

Venn diagram

Accepts two JSON array parameters, treats them as non-ordered sets, and returns a JSON array representing the union of both sets.

Clone this wiki locally