{"id":3874,"date":"2022-12-22T10:24:58","date_gmt":"2022-12-22T10:24:58","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3874"},"modified":"2023-01-25T10:18:53","modified_gmt":"2023-01-25T10:18:53","slug":"items","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3874","title":{"rendered":"Items"},"content":{"rendered":"\n<p>The function <code>items<\/code> is used for taking an object&#8217;s key-value pairs and transforming them into an array of arrays, with each array consisting of the key-value pair&#8217;s key and value. <\/p>\n\n\n\n<h3>Syntax<\/h3>\n\n\n\n<pre title=\"\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">array items(json_object $object)<\/code><\/pre>\n\n\n\n<p>Creates an array of arrays based on the key-value pairs from $object. <\/p>\n\n\n\n<h3>Parameter<\/h3>\n\n\n\n<p><strong>$object<\/strong> The JSON object that should be split into an array of arrays. <\/p>\n\n\n\n<h3>Example<\/h3>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n  \"obj\": {\n    \"b\": \"dataB\",\n    \"c\": \"dataC\",\n    \"d\": \"dataD\"\n  }\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n  itemsArr: items(obj)\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n  \"itemsArr\": [\n    [\n      \"b\",\n      \"dataB\"\n    ],\n    [\n      \"c\",\n      \"dataC\"\n    ],\n    [\n      \"d\",\n      \"dataD\"\n    ]\n  ]\n}<\/code><\/pre>\n\n\n\n<p>In this example, the object <code>obj<\/code> is transformed from being an object into an array of arrays containing both the key and value in each array. <\/p>\n\n\n\n<h3>Notes<\/h3>\n\n\n\n<p><strong>Reaching the value of the key<\/strong><\/p>\n\n\n\n<p>Usually, it is not possible to use the key as a value. However, with the <code>items<\/code> function, you can use an array operator to output the key of a key-value pair. For example, with the result above, you can reach the key &#8220;b&#8221; with <code>itemsArr[0][0]<\/code>. In a transformation, it could look like this: <\/p>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n  itemsArr: items(obj),\n  reachB: $.itemsArr[0][0]\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n  \"itemsArr\": [\n    [\n      \"b\",\n      \"dataB\"\n    ],\n    [\n      \"c\",\n      \"dataC\"\n    ],\n    [\n      \"d\",\n      \"dataD\"\n    ]\n  ],\n  \"reachB\": \"b\"\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The function items is used for taking an object&#8217;s key-value pairs and transforming them into an array of arrays, with each array consisting of the key-value pair&#8217;s key and value. Syntax Creates an array of arrays based on the key-value pairs from $object. Parameter $object The JSON object that should be split into an array [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"parent":271,"menu_order":81,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3874"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3874"}],"version-history":[{"count":12,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3874\/revisions"}],"predecessor-version":[{"id":4340,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3874\/revisions\/4340"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/271"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}