Home Explore Blog CI



postgresql

14th chunk of `doc/src/sgml/json.sgml`
75e1991395bf8a050391dff887ee0fca5e5d5fc73c119a6d0000000100000f82
 id="type-jsonpath-accessors">
   <title><type>jsonpath</type> Accessors</title>
   <tgroup cols="2">
    <colspec colname="col1" colwidth="1*"/>
    <colspec colname="col2" colwidth="2*"/>
    <thead>
     <row>
      <entry>Accessor Operator</entry>
      <entry>Description</entry>
     </row>
    </thead>
    <tbody>
     <row>
      <entry>
       <para>
        <literal>.<replaceable>key</replaceable></literal>
       </para>
       <para>
        <literal>."$<replaceable>varname</replaceable>"</literal>
       </para>
      </entry>
      <entry>
       <para>
        Member accessor that returns an object member with
        the specified key. If the key name matches some named variable
        starting with <literal>$</literal> or does not meet the
        JavaScript rules for an identifier, it must be enclosed in
        double quotes to make it a string literal.
       </para>
      </entry>
     </row>
     <row>
      <entry>
       <para>
        <literal>.*</literal>
       </para>
      </entry>
      <entry>
       <para>
        Wildcard member accessor that returns the values of all
        members located at the top level of the current object.
       </para>
      </entry>
     </row>
     <row>
      <entry>
       <para>
        <literal>.**</literal>
       </para>
      </entry>
      <entry>
       <para>
        Recursive wildcard member accessor that processes all levels
        of the JSON hierarchy of the current object and returns all
        the member values, regardless of their nesting level. This
        is a <productname>PostgreSQL</productname> extension of
        the SQL/JSON standard.
       </para>
      </entry>
     </row>
     <row>
      <entry>
       <para>
        <literal>.**{<replaceable>level</replaceable>}</literal>
       </para>
       <para>
        <literal>.**{<replaceable>start_level</replaceable> to
        <replaceable>end_level</replaceable>}</literal>
       </para>
      </entry>
      <entry>
       <para>
        Like <literal>.**</literal>, but selects only the specified
        levels of the JSON hierarchy. Nesting levels are specified as integers.
        Level zero corresponds to the current object. To access the lowest
        nesting level, you can use the <literal>last</literal> keyword.
        This is a <productname>PostgreSQL</productname> extension of
        the SQL/JSON standard.
       </para>
      </entry>
     </row>
     <row>
      <entry>
       <para>
        <literal>[<replaceable>subscript</replaceable>, ...]</literal>
       </para>
      </entry>
      <entry>
       <para>
        Array element accessor.
        <literal><replaceable>subscript</replaceable></literal> can be
        given in two forms: <literal><replaceable>index</replaceable></literal>
        or <literal><replaceable>start_index</replaceable> to <replaceable>end_index</replaceable></literal>.
        The first form returns a single array element by its index. The second
        form returns an array slice by the range of indexes, including the
        elements that correspond to the provided
        <replaceable>start_index</replaceable> and <replaceable>end_index</replaceable>.
       </para>
       <para>
        The specified <replaceable>index</replaceable> can be an integer, as
        well as an expression returning a single numeric value, which is
        automatically cast to integer. Index zero corresponds to the first
        array element. You can also use the <literal>last</literal> keyword
        to denote the last array element, which is useful for handling arrays
        of unknown length.
       </para>
      </entry>
     </row>
     <row>
      <entry>
       <para>
        <literal>[*]</literal>
       </para>
      </entry>
      <entry>
       <para>
        Wildcard array element accessor that returns all array elements.
       </para>
      </entry>
     </row>
    </tbody>
   </tgroup>
  </table>

 </sect2>
</sect1>

Title: JSONPath Accessors in SQL/JSON
Summary
JSONPath accessors are used to navigate and retrieve data from JSON objects and arrays, including member accessors like .key and .** for recursive access, array element accessors like [subscript] for single elements and [*] for all elements, with support for indexing, slicing, and wildcard selection, allowing for flexible data retrieval in SQL/JSON queries.