<?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>Forem: Pri</title>
    <description>The latest articles on Forem by Pri (@p-rf).</description>
    <link>https://forem.com/p-rf</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%2F2631122%2F93ee049a-e1ba-415f-aabd-523f98e4ec5d.jpg</url>
      <title>Forem: Pri</title>
      <link>https://forem.com/p-rf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/p-rf"/>
    <language>en</language>
    <item>
      <title>Understanding Lambda Functions in Python: Definition, Usage, and Applications</title>
      <dc:creator>Pri</dc:creator>
      <pubDate>Tue, 19 Aug 2025 02:02:32 +0000</pubDate>
      <link>https://forem.com/p-rf/understanding-lambda-functions-in-python-definition-usage-and-applications-1l0b</link>
      <guid>https://forem.com/p-rf/understanding-lambda-functions-in-python-definition-usage-and-applications-1l0b</guid>
      <description>&lt;h3&gt;
  
  
  What is a &lt;code&gt;lambda&lt;/code&gt; Function?
&lt;/h3&gt;

&lt;p&gt;In simple terms, a &lt;code&gt;lambda&lt;/code&gt; function is a small anonymous function, meaning it is defined without a name. A &lt;code&gt;lambda&lt;/code&gt; function can take any amount of arguments; however, it is only able to have one expression. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;lambda&lt;/code&gt; functions are typically used inside of other functions like &lt;code&gt;map()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, or &lt;code&gt;sort()&lt;/code&gt;. It does not need to be assigned to a variable, so it behaves like a function that is defined with &lt;code&gt;def&lt;/code&gt;. It is important to keep in mind that it does not replace &lt;code&gt;def&lt;/code&gt;, as &lt;code&gt;lambda&lt;/code&gt; functions are limited to a single expression.`&lt;/p&gt;

&lt;h3&gt;
  
  
  How Do We Use &lt;code&gt;lambda&lt;/code&gt; Functions?
&lt;/h3&gt;

&lt;h5&gt;
  
  
  Syntax:
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87ksr0onda1nurr8i8jd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F87ksr0onda1nurr8i8jd.png" alt="lambda syntax"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Key Points:
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;lambda&lt;/code&gt; is the keyword used to define the function.&lt;/li&gt;
&lt;li&gt;It can take any number of arguments.&lt;/li&gt;
&lt;li&gt;No return statement needed because it evaluates and returns the value of the expression automatically.&lt;/li&gt;
&lt;li&gt;Usually used for simple functions.&lt;/li&gt;
&lt;li&gt;It is like a "throwaway" function. If writing a complete function is unnecessary and you only need it temporarily, try using a &lt;code&gt;lambda&lt;/code&gt; function!&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Example:
&lt;/h5&gt;

&lt;p&gt;If you were to square a number using a regular function, you would write something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdx12i4d2zcleey5z4aa6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdx12i4d2zcleey5z4aa6.png" alt="regular python function example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;lambda&lt;/code&gt; function equivalent is this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwhlkk9v1s2rcen3ji0lg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwhlkk9v1s2rcen3ji0lg.png" alt="lambda function example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How Are &lt;code&gt;lambda&lt;/code&gt; Functions Useful?
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;lambda&lt;/code&gt; functions show their practicality when used inside of another function. &lt;/p&gt;

&lt;p&gt;If you have a function definition taking in one argument and that argument is multiplied by a number that is unknown, it would look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5wxpkudhfvwp7zmy3b6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5wxpkudhfvwp7zmy3b6h.png" alt="lambda function inside of another function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You are now able to use this function definition to create a function that always doubles... or triples the number you input:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fly0f5cnvjebx1415gswu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fly0f5cnvjebx1415gswu.png" alt="lambda function doubling and tripling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Using a &lt;code&gt;lambda&lt;/code&gt; Function With &lt;code&gt;filter()&lt;/code&gt;, &lt;code&gt;map()&lt;/code&gt;, and &lt;code&gt;sort()&lt;/code&gt;
&lt;/h3&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;filter()&lt;/code&gt; - used to filter specific values from a set of data.
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4j4i0j4ji6p06d7cqfzn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4j4i0j4ji6p06d7cqfzn.png" alt="example using lambda with filter"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;filter(function, iterable)&lt;/code&gt; only keeps the elements for which the function returns True. The &lt;code&gt;lambda x: x % 2 == 0&lt;/code&gt; checks if the numbers are even, one-by-one. &lt;code&gt;filter()&lt;/code&gt; applies the &lt;code&gt;lambda&lt;/code&gt; to every element of &lt;code&gt;numbers&lt;/code&gt; (the list of integers [1-10]) and keeps only the ones that return True (the even ones). &lt;code&gt;filter()&lt;/code&gt; returns an iterator, so we wrap it in &lt;code&gt;list()&lt;/code&gt; to see the filtered results.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;map()&lt;/code&gt; - applies a function to every element.
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ejbu95zhiprn56dzeaq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ejbu95zhiprn56dzeaq.png" alt="example using lambda with map"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;map(function, iterable)&lt;/code&gt; applies the function to every element of the &lt;code&gt;numbers&lt;/code&gt; list. The &lt;code&gt;lambda x: x * 2&lt;/code&gt; doubles each number on that list.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;code&gt;sort()&lt;/code&gt; &lt;strong&gt;With&lt;/strong&gt; &lt;code&gt;key&lt;/code&gt; - sorting logic that is custom.
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fztvpfp6p97twd0lo7kdb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fztvpfp6p97twd0lo7kdb.png" alt="example using lambda with sort"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;sort(key=function)&lt;/code&gt; decides how to order the elements by using the function's return value. The &lt;code&gt;lambda x: len(x)&lt;/code&gt; sorts each fruit by length rather than by alphabetical order.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;lambda&lt;/code&gt; Function Use Cases
&lt;/h3&gt;

&lt;p&gt;In the real world, you may use &lt;code&gt;lambda&lt;/code&gt; with something like filtering an email from a list, so if you were looking for only &lt;code&gt;@gmail.com&lt;/code&gt; addresses, you would be able to keep the &lt;code&gt;@gmail.com&lt;/code&gt; addresses.&lt;/p&gt;

&lt;p&gt;You may use &lt;code&gt;lambda&lt;/code&gt; when mapping through a list to calculate item prices with tax.  That way, &lt;code&gt;lambda&lt;/code&gt; would multiply each price to add a tax.&lt;/p&gt;

&lt;p&gt;Lastly, you could use a &lt;code&gt;lambda&lt;/code&gt; function to sort through people by age, that way your return is the age of each person and &lt;code&gt;sort()&lt;/code&gt; would organize it from youngest to oldest.&lt;/p&gt;

&lt;h5&gt;
  
  
  How will you try using a &lt;code&gt;lambda&lt;/code&gt; function?
&lt;/h5&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
  &lt;iframe src="https://www.youtube.com/embed/IljPHDyBRog"&gt;
  &lt;/iframe&gt;
&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  References
&lt;/h6&gt;

&lt;p&gt;BroCode. (2024, July 14). Learn Python LAMBDA in 6 minutes! 🚮. YouTube. &lt;a href="https://www.youtube.com/watch?v=IljPHDyBRog" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=IljPHDyBRog&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;How are lambdas useful?. Stack Overflow. (2009, May 20). &lt;a href="https://stackoverflow.com/questions/890128/how-are-lambdas-useful" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/890128/how-are-lambdas-useful&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Kumar, R. (2022, September 4). Powerful use-cases of lambda function in Python💪. Medium. &lt;a href="https://medium.com/@ravikumar10593/powerful-use-cases-of-lambda-function-in-python-d4ccefe5f3d2" rel="noopener noreferrer"&gt;https://medium.com/@ravikumar10593/powerful-use-cases-of-lambda-function-in-python-d4ccefe5f3d2&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Reshef, G. (2021, December 8). What is the purpose of lambda expressions?. Discuss Python. &lt;a href="https://discuss.python.org/t/what-is-the-purpose-of-lambda-expressions/12415" rel="noopener noreferrer"&gt;https://discuss.python.org/t/what-is-the-purpose-of-lambda-expressions/12415&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;W3schools.com. W3Schools Online Web Tutorials. (n.d.). &lt;a href="https://www.w3schools.com/python/python_lambda.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/python/python_lambda.asp&lt;/a&gt; &lt;/p&gt;

</description>
      <category>python</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding the React useContext Hook and How to Use It</title>
      <dc:creator>Pri</dc:creator>
      <pubDate>Wed, 23 Jul 2025 01:39:04 +0000</pubDate>
      <link>https://forem.com/p-rf/understanding-the-react-usecontext-hook-and-how-to-use-it-3ph5</link>
      <guid>https://forem.com/p-rf/understanding-the-react-usecontext-hook-and-how-to-use-it-3ph5</guid>
      <description>&lt;p&gt;Prior to the release of the &lt;code&gt;useContext&lt;/code&gt; hook in React 16.8 on February 6th, 2019, developers relied on prop drilling, render props, and third-party libraries. While functional, these approaches led to several issues, such as reduced readability and maintainability (prop drilling), more complex and less intuitive components (render props), and added complexity with boilerplate code (third-party libraries). The &lt;code&gt;useContext&lt;/code&gt; hook offers an efficient and seamless option to share state between components.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the &lt;code&gt;useContext&lt;/code&gt; hook?
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;useContext&lt;/code&gt; hook provides a simpler way to pass data through the component tree without manually passing props at every level. In a typical React application, data is passed from a parent component to a child via props. This can be inefficient when certain values are required by &lt;em&gt;multiple components&lt;/em&gt; across the application. The &lt;code&gt;useContext&lt;/code&gt; hook simplifies this process, eliminating the need to explicitly pass props through every level of the tree.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why use &lt;code&gt;useContext&lt;/code&gt; instead of props?
&lt;/h3&gt;

&lt;p&gt;Since &lt;code&gt;useContext&lt;/code&gt; is designed to share data, it can be considered "global" for a component tree—much like a theme, preferred language, or authenticated user. By using the &lt;code&gt;useContext&lt;/code&gt; hook, you avoid passing props through intermediate components. If your data needs to be accessible by &lt;em&gt;many&lt;/em&gt; components at various nesting levels and you want to avoid prop drilling, &lt;code&gt;useContext&lt;/code&gt; is the ideal solution.&lt;/p&gt;

&lt;p&gt;Example showing &lt;strong&gt;props&lt;/strong&gt; being passed through nested components:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0fta35hnkfhk3dwn9me.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa0fta35hnkfhk3dwn9me.png" alt="Example of props through nested components"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How do you use the &lt;code&gt;useContext&lt;/code&gt; hook?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create context:&lt;/strong&gt; Import &lt;code&gt;createContext&lt;/code&gt; and initialize it.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, createContext } from "react";
import ReactDOM from "react-dom/client";

const UserContext = createContext()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Context Provider:&lt;/strong&gt; Wrap the components that need access to the context with a &lt;code&gt;UserContext.Provider&lt;/code&gt;. All child components within this tree will have access to the context.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function ComponentOne() {
  const [user, setUser] = useState("John Doe");

  return (
    &amp;lt;UserContext.Provider value={user}&amp;gt;
      &amp;lt;h1&amp;gt;{`Hello ${user}!`}&amp;lt;/h1&amp;gt;
      &amp;lt;ComponentTwo user={user} /&amp;gt;
    &amp;lt;/UserContext.Provider&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Using the &lt;code&gt;useContext&lt;/code&gt; hook:&lt;/strong&gt; Include &lt;code&gt;useContext&lt;/code&gt; in the import statement for the component where you need the data. As long as you do this, you will be able to access the data in any component. Make sure to include a function declaration and a variable name.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, createContext, useContext } from "react";

function ComponentFive() {
  const user = useContext(UserContext);

  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Component Five&amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;{`Hello ${user} again!`}&amp;lt;/h2&amp;gt;
    &amp;lt;/&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Complete Example Using the useContext Hook
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState, createContext, useContext } from "react";  // import createContext
import ReactDOM from "react-dom/client";

const UserContext = createContext();  // initialize createContext

function ComponentOne() {
  const [user, setUser] = useState("John Doe");

  return (  // wrap the child components in Context Provider and include the state value
    &amp;lt;UserContext.Provider value={user}&amp;gt; 
      &amp;lt;h1&amp;gt;{`Hello ${user}!`}&amp;lt;/h1&amp;gt;
      &amp;lt;ComponentTwo /&amp;gt;
    &amp;lt;/UserContext.Provider&amp;gt;
  );
}

// all components will have access to the user context
// to use useContext in a child component, we need to access it using the useContext Hook
function ComponentTwo() {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Component Two&amp;lt;/h1&amp;gt;
      &amp;lt;ComponentThree /&amp;gt;
    &amp;lt;/&amp;gt;
  );
}

function ComponentThree() {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Component Three&amp;lt;/h1&amp;gt;
      &amp;lt;ComponentFour /&amp;gt;
    &amp;lt;/&amp;gt;
  );
}

function ComponentFour() {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Component Four&amp;lt;/h1&amp;gt;
      &amp;lt;ComponentFive /&amp;gt;
    &amp;lt;/&amp;gt;
  );
}

//  include the useContext hook in the import statement for the component you want the data in
import { useState, createContext, useContext } from "react";

function ComponentFive() { //  you can access the user context in all components where you import the data
  const user = useContext(UserContext);

  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;Component Five&amp;lt;/h1&amp;gt;
      &amp;lt;h2&amp;gt;{`Hello ${user} again!`}&amp;lt;/h2&amp;gt;
    &amp;lt;/&amp;gt;
  );
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(&amp;lt;ComponentOne /&amp;gt;);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;  &lt;iframe src="https://www.youtube.com/embed/lnL6gRkQ5g8"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h5&gt;
  
  
  References
&lt;/h5&gt;

&lt;p&gt;Context. React. (n.d.). &lt;a href="https://legacy.reactjs.org/docs/context.html#:%7E:text=Passing%20Data%20Deeply%20with%20Context,every%20level%20of%20the%20tree" rel="noopener noreferrer"&gt;https://legacy.reactjs.org/docs/context.html#:~:text=Passing%20Data%20Deeply%20with%20Context,every%20level%20of%20the%20tree&lt;/a&gt;. &lt;br&gt;
Pedro. (2020, October 2). UseContext Hook Tutorial In ReactJS | Global States. YouTube. &lt;a href="https://www.youtube.com/watch?v=lnL6gRkQ5g8" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=lnL6gRkQ5g8&lt;/a&gt; &lt;br&gt;
React useContext Hook. W3Schools Online Web Tutorials. (n.d.). &lt;a href="https://www.w3schools.com/react/react_usecontext.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/react/react_usecontext.asp&lt;/a&gt; &lt;br&gt;
ReactJS useContext Hook. GeeksforGeeks. (2025, March 5). &lt;a href="https://www.geeksforgeeks.org/reactjs/reactjs-usecontext-hook/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/reactjs/reactjs-usecontext-hook/&lt;/a&gt; &lt;/p&gt;

</description>
      <category>react</category>
      <category>usecontext</category>
      <category>reactnative</category>
      <category>reacthooks</category>
    </item>
    <item>
      <title>A Straightforward Guide to Building and Using a JSON Database File</title>
      <dc:creator>Pri</dc:creator>
      <pubDate>Tue, 31 Dec 2024 00:43:07 +0000</pubDate>
      <link>https://forem.com/p-rf/a-straightforward-guide-to-building-and-using-a-json-database-file-5a3h</link>
      <guid>https://forem.com/p-rf/a-straightforward-guide-to-building-and-using-a-json-database-file-5a3h</guid>
      <description>&lt;h3&gt;
  
  
  What is a &lt;code&gt;db.json&lt;/code&gt; file?
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;db.json&lt;/code&gt; file is a JavaScript Object Notation (JSON) file that is used to store and transport organized data in a format that is easy to read; often when data is sent from a server to a web page.&lt;/p&gt;

&lt;p&gt;JSON is language independent, meaning the JSON syntax is developed from JavaScript object notation syntax, but the JSON format is only in text format. The code used for reading and creating JSON data can be written in other programming languages.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/cj3h3Fb10QY"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Why is a &lt;code&gt;db.json&lt;/code&gt; file ideal?
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;db.json&lt;/code&gt; file is lightweight, easy to read, and does not require a complex setup, which makes it easy for developers to understand and modify data. &lt;code&gt;db.json&lt;/code&gt; files are ideal for local development or prototyping frontend applications. During development, data often needs to be stored somewhere temporarily without needing to set up a full database; a &lt;code&gt;db.json&lt;/code&gt; file provides that simple solution.&lt;/p&gt;

&lt;p&gt;Certain tools, such as a JSON Server can transform a &lt;code&gt;db.json&lt;/code&gt; file into a completely functional mock REST API. A mock REST API server "imitates a real API server by providing realistic responses to requests" (&lt;em&gt;API Mocking Guide and Online Mock API Server Testing&lt;/em&gt;). This allows frontend developers to test API calls without a backend and mock-up a model of an application with realistic API responses.&lt;/p&gt;

&lt;p&gt;For example, a &lt;code&gt;db.json&lt;/code&gt; file like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"topFiveUniversities"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"University of Oxford"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Massachusetts Institute of Technology"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Harvard University"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Princeton University"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"University of Cambridge"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can get a result in API endpoints like:&lt;br&gt;
&lt;strong&gt;GET /topFiveUniversities&lt;/strong&gt;: Retrieves the full list of universities&lt;br&gt;
&lt;strong&gt;POST /topFiveUniversities&lt;/strong&gt;: Adds a new university&lt;br&gt;
&lt;strong&gt;PUT /topFiveUniversities/1&lt;/strong&gt;: Updates the university with id:1&lt;br&gt;
&lt;strong&gt;DELETE /topFiveUniversities/1&lt;/strong&gt;: Deletes the university with id:1&lt;/p&gt;
&lt;h3&gt;
  
  
  What is the structure of a &lt;code&gt;db.json&lt;/code&gt; file?
&lt;/h3&gt;

&lt;p&gt;The following syntax defines dog breeds object, which are an array of three dog breed records (objects):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"dogBreeds"&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"breed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bernese Mountain Dog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"origin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Switzerland"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"breed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Dogo Argentino"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"origin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Argentina"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"breed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Chihuahua"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"origin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Mexico"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The top-level key is "dogBreeds" (an array). The array items are each item in the array, which are objects with two key-value pairs "breed" and "origin."&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Be sure to use camelCase or snake_case and avoid spaces in keys (e.g., "dog breeds"), as it can cause difficulties when constructing URLs and potential issues when accessing the keys in your code.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Rules of JSON Syntax
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The data is organized as name/value pairs&lt;/li&gt;
&lt;li&gt;The commas separate elements in arrays or key-value pairs in objects (except the last one)&lt;/li&gt;
&lt;li&gt;The curly braces hold the objects&lt;/li&gt;
&lt;li&gt;The square brackets hold the arrays&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fson6kpt5kura6v5cgqv5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fson6kpt5kura6v5cgqv5.png" alt="Rules of JSON Syntax Image" width="800" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Breakdown of JSON Data
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Name and Value
&lt;/h4&gt;

&lt;p&gt;Name or value pairs are used in JSON data writing, much like the properties of JavaScript. A name or value pair has a field name in double quotation marks (" "), followed by a colon (:), followed by a value in double quotes (" "):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"breed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Bernese Mountain Dog"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;JSON names must have double quotes; JavaScript does not.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Objects
&lt;/h4&gt;

&lt;p&gt;The objects in a JSON file are written in curly braces. They can contain more than one name or value pairs, like in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"breed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Bernese Mountain Dog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"origin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Switzerland"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Each name/value pairs should be separated by a comma and space.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Arrays
&lt;/h4&gt;

&lt;p&gt;The arrays in a JSON file are written in square brackets. An array can contain objects, like in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"dogBreeds"&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"breed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bernese Mountain Dog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"origin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Switzerland"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"breed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Dogo Argentino"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"origin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Argentina"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"breed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Chihuahua"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"origin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Mexico"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As seen above, the object "dogBreeds" is an array which contains three objects. Each object is stored information of a specific breed and its origin.&lt;/p&gt;

&lt;h4&gt;
  
  
  Some things to Keep in mind when building a `db.json file
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If you open a curly brace &lt;code&gt;{}&lt;/code&gt; or square bracket &lt;code&gt;[]&lt;/code&gt;, make sure to close them.&lt;/li&gt;
&lt;li&gt;Include commas between array or objects&lt;/li&gt;
&lt;li&gt;Use double quotes (" ") for strings&lt;/li&gt;
&lt;li&gt;Do not include comments (JSON does not allow them)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Transforming JSON Text into a JavaScript Object
&lt;/h3&gt;

&lt;p&gt;It is useful to convert a JSON text to a JavaScript object in cases where you may need to work with structured data in a more interactive manner. JSON is commonly used to read data from a web server and display it on a web page. You can use a string as input to structure it in a simple way. You can do this by creating a JavaScript string that contains JSON syntax:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F22ewmp8ig52ocovnt1fl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F22ewmp8ig52ocovnt1fl.png" alt="Transforming JSON Text 1" width="743" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use the JavaScript built-in function &lt;code&gt;JSON.parse()&lt;/code&gt; to change the string into a JavaScript object:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpqs1d7lr3opku1pzjie.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgpqs1d7lr3opku1pzjie.png" alt="Transforming JSON Text 2" width="743" height="67"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, in your page, use the new JavaScript object:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkyt3abuvbzdojsnqd1kz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkyt3abuvbzdojsnqd1kz.png" alt="Transforming JSON Text 3" width="743" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Using a &lt;code&gt;db.json&lt;/code&gt; file with a project
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; and &lt;a href="https://www.npmjs.com/" rel="noopener noreferrer"&gt;npm&lt;/a&gt; will need to be installed on your computer. Continue onto the following steps to set up and use JSON Server in your application:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Install the JSON Server&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In your terminal or command prompt, navigate to your project directory and type:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;npm install -g json-server&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This will globally install the JSON Server in your computer. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Create a JSON File&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In your project directory, create a JSON file using VSCode or a code editor of your choice. Your JSON file should have a .json file extension, such as &lt;code&gt;db.json&lt;/code&gt;. This is where you will write your JSON data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Construct Your Data&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Establish your data inside the &lt;code&gt;db.json&lt;/code&gt; file as an array of objects or an object with nested objects. Each object should have a unique id, as it represents a data entity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Start the JSON Server&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start your JSON Server by typing the following into your terminal:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;json-server --watch db.json&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This will run by default on &lt;code&gt;http://localhost:3000&lt;/code&gt;. Access the API at &lt;code&gt;http://localhost:3000&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;p&gt;“API Mocking Guide and Online Mock API Server Testing.” &lt;em&gt;Stoplight - A Smartbear Company&lt;/em&gt;, &lt;a href="https://stoplight.io/mock-api-guide#:%7E:text=A%20mock%20API%20server%20imitates,types%2C%20objects%2C%20and%20arrays" rel="noopener noreferrer"&gt;https://stoplight.io/mock-api-guide#:~:text=A%20mock%20API%20server%20imitates,types%2C%20objects%2C%20and%20arrays&lt;/a&gt;. Accessed Dec. 2024. &lt;/p&gt;

&lt;p&gt;“JavaScript JSON.” &lt;em&gt;W3Schools Online Web Tutorials&lt;/em&gt;, &lt;a href="http://www.w3schools.com/js/js_json.asp" rel="noopener noreferrer"&gt;www.w3schools.com/js/js_json.asp&lt;/a&gt;. Accessed Dec. 2024. &lt;/p&gt;

&lt;p&gt;Ofoegbu, Juliet. “How to Use JSON Server for Front-End Development.” &lt;em&gt;freeCodeCamp.Org&lt;/em&gt;, freeCodeCamp.org, 21 Aug. 2023, &lt;a href="http://www.freecodecamp.org/news/json-server-for-frontend-development/" rel="noopener noreferrer"&gt;www.freecodecamp.org/news/json-server-for-frontend-development/&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;What Is JSON | Explained&lt;/em&gt;, Hostinger Academy, 24 Nov. 2022, &lt;a href="https://youtu.be/cj3h3Fb10QY?feature=shared" rel="noopener noreferrer"&gt;https://youtu.be/cj3h3Fb10QY?feature=shared&lt;/a&gt;. Accessed July 2024. &lt;/p&gt;

&lt;p&gt;“World University Rankings.” &lt;em&gt;Times Higher Education (THE)&lt;/em&gt;, 16 Dec. 2024, &lt;a href="http://www.timeshighereducation.com/world-university-rankings/latest/world-ranking" rel="noopener noreferrer"&gt;www.timeshighereducation.com/world-university-rankings/latest/world-ranking&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>dbjson</category>
      <category>json</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
