<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rezigned</title>
    <description>The latest articles on DEV Community by Rezigned (@rezigned).</description>
    <link>https://dev.to/rezigned</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F310480%2F41f1568f-4c25-45ee-8fb6-7a3f3664edaf.jpeg</url>
      <title>DEV Community: Rezigned</title>
      <link>https://dev.to/rezigned</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rezigned"/>
    <language>en</language>
    <item>
      <title>Mousemory - remembers mouse position across multiple monitors</title>
      <dc:creator>Rezigned</dc:creator>
      <pubDate>Sat, 02 Oct 2021 15:28:11 +0000</pubDate>
      <link>https://dev.to/rezigned/mousemory-remembers-mouse-position-across-multiple-monitors-20h9</link>
      <guid>https://dev.to/rezigned/mousemory-remembers-mouse-position-across-multiple-monitors-20h9</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NjK3R2_Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6q192ykrmbvyy7af5opi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NjK3R2_Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6q192ykrmbvyy7af5opi.png" alt="Mousemory"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i3JOwpme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/rezigned"&gt;
        rezigned
      &lt;/a&gt; / &lt;a href="https://github.com/rezigned/Mousemory"&gt;
        Mousemory
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Mousemory remembers cursor position across multiple monitors.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Introducing &lt;a href="https://github.com/rezigned/Mousemory"&gt;Mousemory&lt;/a&gt;! A simple macOS utility app that remembers your cursor positions across multiple monitors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lV07GIoE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://rezigned.com/images/mousemory-v1.0/demo.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lV07GIoE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://rezigned.com/images/mousemory-v1.0/demo.gif" alt="demo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since COVID-19 pandemic. Most people started working from home (including me). If you have a setup where you have more than 1 monitor. You might have felt like me.&lt;/p&gt;

&lt;p&gt;When switching between monitors (via &lt;code&gt;cmd + tab&lt;/code&gt;). I've to drag the cursor from previous screen to the new screen all the time (which can cause repetitive strain injury). Why can't it just remembers the previous position and then restore it when switching back?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4Ng8X6TT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://rezigned.com/images/mousemory-v1.0/before.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Ng8X6TT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://rezigned.com/images/mousemory-v1.0/before.gif" alt="before"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, I was searching for these kind of apps but couldn't find one. Then, I decided to make it myself. It's also a good chance for me to learn more about &lt;code&gt;Swift&lt;/code&gt; + &lt;code&gt;macOS&lt;/code&gt; development.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KdBhRpRo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://rezigned.com/images/mousemory-v1.0/after.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KdBhRpRo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://rezigned.com/images/mousemory-v1.0/after.gif" alt="after"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; (Icons made by &lt;a href="https://www.freepik.com" title="Freepik"&gt;Freepik&lt;/a&gt; from &lt;a href="https://www.flaticon.com/" title="Flaticon"&gt;www.flaticon.com&lt;/a&gt;)&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;You can check it out here &lt;a href="https://github.com/rezigned/Mousemory"&gt;https://github.com/rezigned/Mousemory&lt;/a&gt;. (or &lt;a href="https://github.com/rezigned/Mousemory/releases"&gt;download here&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/rezigned" rel="nofollow"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---VnT51U1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.buymeacoffee.com/button-api/%3Ftext%3DBuy%2520me%2520a%2520coffee%26emoji%3D%26slug%3Drezigned%26button_colour%3D40DCA5%26font_colour%3Dffffff%26font_family%3DBree%26outline_colour%3D000000%26coffee_colour%3D208A51"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>swift</category>
      <category>github</category>
      <category>opensource</category>
    </item>
    <item>
      <title>An Introduction to JSON Selector</title>
      <dc:creator>Rezigned</dc:creator>
      <pubDate>Sat, 25 Jan 2020 07:57:08 +0000</pubDate>
      <link>https://dev.to/rezigned/an-intoduction-to-json-selector-1mho</link>
      <guid>https://dev.to/rezigned/an-intoduction-to-json-selector-1mho</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;small&gt;Cover: &lt;a href="https://unsplash.com/photos/l5Tzv1alcps"&gt;https://unsplash.com/photos/l5Tzv1alcps&lt;/a&gt;&lt;small&gt;&lt;/small&gt;&lt;/small&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is JSON selector?
&lt;/h2&gt;

&lt;p&gt;It's a library/tool that allows you to select values from JSON object using specific query syntax (or you can think of it as a &lt;strong&gt;CSS Selector&lt;/strong&gt; but it's for JSON). &lt;/p&gt;

&lt;p&gt;In this post, we'll go through some of the most popular libraries and see how we can use it to select our data.&lt;/p&gt;

&lt;h3&gt;
  
  
  What about Optional Chaining?
&lt;/h3&gt;

&lt;p&gt;Before we begin. Let's take a look at ECMAScript's new proposal &lt;a href="https://tc39.es/proposal-optional-chaining/"&gt;Optional Chaining&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When working with JS Object. Most of the time we'll come across these problems.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bangkok&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="na"&gt;friends&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;How can I access &lt;code&gt;city&lt;/code&gt; property safely? One could do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;city&lt;/span&gt; &lt;span class="c1"&gt;// "Bangkok"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But what if the property that we want is in much deeper level? Then you would have to do many &lt;code&gt;a &amp;amp;&amp;amp; a.b &amp;amp;&amp;amp; a.b.c ...&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Thus, the birth of &lt;strong&gt;Optional Chaining Operator&lt;/strong&gt; (&lt;code&gt;?.&lt;/code&gt;)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Optional Chaining Operator allows a developer to handle many of those cases without repeating themselves and/or assigning intermediate results in temporary variables:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's see them in action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;city&lt;/span&gt; &lt;span class="c1"&gt;// Bangkok&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That's neat. It's much easier to access the nested property. But what if the target property is not an &lt;code&gt;Object&lt;/code&gt;? (e.g. &lt;code&gt;Array&lt;/code&gt;, etc.). Then the above solution won't work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;friends&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt; &lt;span class="c1"&gt;// ???&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  JSON Selectors
&lt;/h2&gt;

&lt;p&gt;The above problem can be solved with &lt;strong&gt;JSON selector&lt;/strong&gt;. With this, we can now have more flexible and powerful ways to access our JSON object. We'll start with a basic JSON data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;Here's the typical JSON object structure that everyone is familiar with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;friends&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;friends&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Joe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's say we want to get all user ids.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We'll take a look at how to achieve the above result by exploring some of the popular libraries/tools out there.&lt;/p&gt;

&lt;h3&gt;
  
  
  JSONPath
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/jsonpath"&gt;JSONPath&lt;/a&gt;'s idea is to bring the power of &lt;a href="https://en.wikipedia.org/wiki/XPath"&gt;XPath&lt;/a&gt; (XML-based path selector) to Javascript world.&lt;/p&gt;

&lt;h4&gt;
  
  
  Selecting values
&lt;/h4&gt;

&lt;p&gt;With &lt;strong&gt;JSONPath&lt;/strong&gt; we can achieve that by using the following path selector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;jp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;jsonpath&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;jp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;$.users[*].id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It also supports &lt;strong&gt;array slice&lt;/strong&gt; feature. In the following example it will slice an array from 0th index to 1st index (coresponds to &lt;code&gt;array.slice(0, 1)&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;jp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;$.users[:1].id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;One of the problem that I stumbled upon is that. It always returns array of values eventhough I explicity specify the index of an array e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;jq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;$.users[0].id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1], should just return single element i.e. 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There're many path expressions that you might want to check it out &lt;a href="https://goessner.net/articles/JsonPath/index.html#e2"&gt;https://goessner.net/articles/JsonPath/index.html#e2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's the &lt;a href="https://jsonpath.com/"&gt;playground&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  jq
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://stedolan.github.io/jq/"&gt;jq&lt;/a&gt; is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;jq&lt;/strong&gt; is very popular and powerful one. It can even transform your output and has become part of many command line tools. You've probably seen it in many tutorials that deal with &lt;code&gt;cli&lt;/code&gt; and &lt;code&gt;json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's take a quick look.&lt;/p&gt;

&lt;h4&gt;
  
  
  Selecting values
&lt;/h4&gt;

&lt;p&gt;A simple example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;curl &amp;lt;url&amp;gt; | jq &lt;span class="s1"&gt;'.users[].id'&lt;/span&gt; // &lt;span class="o"&gt;[&lt;/span&gt;1, 2]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Transforming values
&lt;/h4&gt;

&lt;p&gt;It can do more than just selecting. In the example below, we can even produce a new JSON output with pipe operators (&lt;code&gt;|&lt;/code&gt;).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;curl &amp;lt;url&amp;gt; | jq &lt;span class="s1"&gt;'.users[0] | { "id": .id }'&lt;/span&gt; // &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"id"&lt;/span&gt;: 1 &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt; It selects the first element of &lt;code&gt;users&lt;/code&gt; array and then creates a new object by using &lt;code&gt;id&lt;/code&gt; property of the result from previous command. &lt;/p&gt;

&lt;p&gt;Here's the &lt;a href="https://jqplay.org/"&gt;playground&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  @gizt/selector
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://github.com/gizt/selector"&gt;@gizt/selector&lt;/a&gt; &lt;em&gt;disclaimer&lt;/em&gt;: I wrote this library a while ago. Because I just want a selector with a simple syntax that every developer who uses Javascript is already familiar with.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let's take a quick tour.&lt;/p&gt;

&lt;h4&gt;
  
  
  Selecting values
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@gizt/selector&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users[].id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2]&lt;/span&gt;

&lt;span class="c1"&gt;// single value&lt;/span&gt;
&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users[0].id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 1 (not [1])&lt;/span&gt;

&lt;span class="c1"&gt;// go deeper&lt;/span&gt;
&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users[].friends[].name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ["John", "Joe"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Notice that we don't have to add a prefix like &lt;code&gt;.&lt;/code&gt; or &lt;code&gt;$&lt;/code&gt; at the beginning of the query. &lt;/p&gt;

&lt;h5&gt;
  
  
  Globing the keys
&lt;/h5&gt;

&lt;p&gt;I believe that every developers is already familiar with &lt;code&gt;*&lt;/code&gt; wildcard symbol. We can use it to filter our result even further.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Select any properties&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the following example, we select any properties of &lt;code&gt;user&lt;/code&gt; object i.e. &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;friends&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users[].*&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="c1"&gt;// users[0].id&lt;/span&gt;
  &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// users[0].friends&lt;/span&gt;
  &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;
  &lt;span class="c1"&gt;// users[1].id&lt;/span&gt;
  &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// users[1].friends&lt;/span&gt;
  &lt;span class="p"&gt;[{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Joe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Select only matched prefix/suffix&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here we want only property that start with &lt;code&gt;i&lt;/code&gt;. In this case it only matches &lt;code&gt;id&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users[].i*&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [1, 2]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When we want to match a suffix we can simpy do. It'll match properties that end with &lt;code&gt;ends&lt;/code&gt; i.e. &lt;code&gt;friends&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users[].*ends&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// [[ friend 1 ], [ friend 2 ]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The syntax is just make any developer feels at home. No need to remember any special characters. Just plain JSON notation and &lt;code&gt;glob&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gizt.github.io/selector/"&gt;Playground&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;I just gave a quick overview on &lt;strong&gt;JSON Selector&lt;/strong&gt; topic which covered some of the popular libraries out there (including my own :p). Some people might not aware of these tools/libraries which we can leverage to solve everyday's problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;P.S&lt;/strong&gt; it's my first article here. Hope you guys enjoy it.&lt;/p&gt;

&lt;p&gt;If you have any libraries and feedback. Please share and comment. Have a good day :).&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
