<?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: Illia Pantsyr</title>
    <description>The latest articles on DEV Community by Illia Pantsyr (@panilya).</description>
    <link>https://dev.to/panilya</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%2F660372%2F3e982e29-2f61-4cf1-b46a-f562648130e4.jpeg</url>
      <title>DEV Community: Illia Pantsyr</title>
      <link>https://dev.to/panilya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/panilya"/>
    <language>en</language>
    <item>
      <title>When to use Cloudflare Workers for Edge Processing</title>
      <dc:creator>Illia Pantsyr</dc:creator>
      <pubDate>Tue, 13 Jan 2026 17:15:35 +0000</pubDate>
      <link>https://dev.to/panilya/when-to-use-cloudflare-workers-for-edge-processing-52n</link>
      <guid>https://dev.to/panilya/when-to-use-cloudflare-workers-for-edge-processing-52n</guid>
      <description>&lt;p&gt;Not every request needs to hit your backend. Some operations—metadata extraction, URL validation, lightweight transformations—are better served at the edge, closer to your users. Cloudflare Workers provide a compelling platform for these use cases, but knowing when to reach for them (and when not to) is the real skill.&lt;/p&gt;

&lt;p&gt;In this article, I'll share a decision framework for edge computing based on my experience building services at &lt;a href="https://allscreenshots.com" rel="noopener noreferrer"&gt;Allscreenshots&lt;/a&gt;, where we use Workers for link preview metadata extraction while keeping heavier operations in our main backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Are Cloudflare Workers?
&lt;/h2&gt;

&lt;p&gt;Cloudflare Workers are serverless functions that run on Cloudflare's global edge network—over 300 data centers worldwide. Unlike traditional serverless (AWS Lambda, Google Cloud Functions), Workers execute at the edge, meaning your code runs in the data center closest to each user.&lt;/p&gt;

&lt;p&gt;Key characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No cold starts&lt;/strong&gt;: V8 isolates spin up in under 5ms&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Global by default&lt;/strong&gt;: Deployed to all edge locations automatically&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lightweight runtime&lt;/strong&gt;: JavaScript/TypeScript with Web APIs (fetch, crypto, streams)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Request-based pricing&lt;/strong&gt;: Pay per invocation, not per server&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Decision Framework
&lt;/h2&gt;

&lt;p&gt;Before moving functionality to the edge, ask these questions:&lt;/p&gt;

&lt;h3&gt;
  
  
  Move to the Edge When:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. The operation is stateless&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Edge functions excel at request-in, response-out operations. If you need to read from or write to a database, you're adding latency that negates edge benefits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Good fit: Parse HTML and extract meta tags
Poor fit: Look up user preferences from PostgreSQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Latency matters more than compute power&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Edge locations have limited CPU time (typically 10-50ms for free tiers, more for paid). If your operation is lightweight but latency-sensitive, edge wins.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Good fit: Validate and normalize a URL
Poor fit: Generate a PDF report
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. You need geographic distribution without managing infrastructure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Deploying to 300+ locations manually is impractical. Edge platforms handle this automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Good fit: Serve different content based on user location
Poor fit: Run a long-lived WebSocket server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. The workload is read-heavy and cacheable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Edge computing pairs well with CDN caching. Compute once, cache at the edge, serve many.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Good fit: Transform and cache API responses
Poor fit: Process unique, non-cacheable data per request
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Keep in Your Backend When:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You need persistent connections (databases, WebSockets)&lt;/li&gt;
&lt;li&gt;Operations are CPU-intensive (image processing, ML inference)&lt;/li&gt;
&lt;li&gt;You require more than a few seconds of execution time&lt;/li&gt;
&lt;li&gt;The operation needs access to your internal services&lt;/li&gt;
&lt;li&gt;State management is complex&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Edge Use Cases
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Metadata Extraction
&lt;/h3&gt;

&lt;p&gt;Fetching a URL and parsing its HTML for Open Graph tags, Twitter Cards, or structured data. The operation is stateless, involves network I/O to external sites, and benefits from being geographically close to both the user and target server.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Request Validation and Transformation
&lt;/h3&gt;

&lt;p&gt;Validating API requests, normalizing URLs, or transforming payloads before they reach your backend. Reject bad requests at the edge before they consume backend resources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Example: URL normalization at the edge&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;normalizeUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http://&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://&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="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Remove trailing slashes, normalize www, etc.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;origin&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;parsed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;+$/&lt;/span&gt;&lt;span class="p"&gt;,&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;h3&gt;
  
  
  3. API Response Shaping
&lt;/h3&gt;

&lt;p&gt;Your backend returns verbose JSON, but mobile clients need a slim payload. Transform at the edge:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Backend returns full user object&lt;/span&gt;
&lt;span class="c1"&gt;// Edge returns only what the client needs&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;shapeResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fullResponse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;FullUser&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;SlimUser&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;fullResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;fullResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;display_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;avatar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;fullResponse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;avatar_url&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;h3&gt;
  
  
  4. A/B Testing and Feature Flags
&lt;/h3&gt;

&lt;p&gt;Route requests to different backends or modify responses based on cookies, headers, or random assignment—all without touching your application code.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Authentication Token Validation
&lt;/h3&gt;

&lt;p&gt;Validate JWTs at the edge before requests reach your backend. Invalid tokens never consume backend resources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Pseudo-code for JWT validation at edge&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;validateToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Authorization&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)?.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bearer &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="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;isValidJwt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Unauthorized&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="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;401&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Token valid, forward to backend&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&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;h2&gt;
  
  
  Architecture Pattern: Edge + Backend
&lt;/h2&gt;

&lt;p&gt;The pattern that works well: &lt;strong&gt;edge for preprocessing, backend for heavy lifting&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   Client    │────▶│    Edge     │────▶│   Backend   │
│             │     │   Worker    │     │             │
└─────────────┘     └─────────────┘     └─────────────┘
                          │
                    ┌─────┴─────┐
                    │           │
              Stateless    Lightweight
              operations   transforms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;At the edge:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validate requests&lt;/li&gt;
&lt;li&gt;Extract metadata from external URLs&lt;/li&gt;
&lt;li&gt;Transform/filter responses&lt;/li&gt;
&lt;li&gt;Handle CORS&lt;/li&gt;
&lt;li&gt;Cache static computations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;In the backend:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Database operations&lt;/li&gt;
&lt;li&gt;File storage&lt;/li&gt;
&lt;li&gt;Job queues and async processing&lt;/li&gt;
&lt;li&gt;Browser automation&lt;/li&gt;
&lt;li&gt;Business logic requiring state&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Trade-offs to Consider
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bundle size matters&lt;/strong&gt;: Workers have size limits. Heavy libraries may not fit or may blow your CPU budget. Prefer lightweight, purpose-built code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No traditional debugging&lt;/strong&gt;: You can't attach a debugger. Rely on logging, Cloudflare's dashboard, and local development with Wrangler.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Limited execution time&lt;/strong&gt;: Workers have CPU time limits (10-50ms on free tier, higher on paid). Long-running operations don't fit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Statelessness is strict&lt;/strong&gt;: No filesystem, no persistent memory between requests. Need state? Use Cloudflare KV, Durable Objects, or call your backend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vendor lock-in&lt;/strong&gt;: Workers use Web APIs but have Cloudflare-specific features. Porting to another platform requires some rewriting.&lt;/p&gt;

&lt;h2&gt;
  
  
  When NOT to Use Workers
&lt;/h2&gt;

&lt;p&gt;I've seen teams move everything to the edge and regret it. Avoid Workers for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Database-heavy operations&lt;/strong&gt;: Every DB call adds latency. If you're making 5+ queries, keep it in your backend near the database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CPU-intensive processing&lt;/strong&gt;: Image resizing, video transcoding, ML inference—these need more compute than edge provides.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complex orchestration&lt;/strong&gt;: Multi-step workflows with error handling and retries belong in your backend.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Operations requiring secrets rotation&lt;/strong&gt;: While Workers support secrets, complex credential management is easier in traditional backends.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Performance Expectations
&lt;/h2&gt;

&lt;p&gt;Typical characteristics for well-designed Workers:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Typical Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Worker execution time&lt;/td&gt;
&lt;td&gt;1-10ms (excluding external fetches)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cold start&lt;/td&gt;
&lt;td&gt;&amp;lt;5ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Total latency&lt;/td&gt;
&lt;td&gt;Dominated by external API calls&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bundle size target&lt;/td&gt;
&lt;td&gt;&amp;lt;1MB (smaller is better)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The worker itself is rarely the bottleneck. External network calls dominate response time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Cloudflare's Wrangler CLI makes deployment straightforward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; wrangler

&lt;span class="c"&gt;# Create project&lt;/span&gt;
wrangler init my-worker

&lt;span class="c"&gt;# Develop locally&lt;/span&gt;
wrangler dev

&lt;span class="c"&gt;# Deploy globally&lt;/span&gt;
wrangler deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your code deploys to 300+ locations in seconds. No regions to configure, no scaling to manage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Cloudflare Workers shine for stateless, latency-sensitive operations that benefit from geographic distribution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Metadata extraction&lt;/li&gt;
&lt;li&gt;Request validation and transformation&lt;/li&gt;
&lt;li&gt;API response shaping&lt;/li&gt;
&lt;li&gt;A/B testing and feature flags&lt;/li&gt;
&lt;li&gt;Token validation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before moving functionality to the edge, verify it's truly stateless and lightweight. The edge isn't a replacement for your backend—it's a complement that handles the quick stuff so your backend can focus on what it does best.&lt;/p&gt;

&lt;p&gt;Start with one simple use case, measure the impact, and expand from there.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Convert JSON to TOON: 4 Methods Compared</title>
      <dc:creator>Illia Pantsyr</dc:creator>
      <pubDate>Mon, 08 Dec 2025 22:48:38 +0000</pubDate>
      <link>https://dev.to/panilya/how-to-convert-json-to-toon-4-methods-compared-c0f</link>
      <guid>https://dev.to/panilya/how-to-convert-json-to-toon-4-methods-compared-c0f</guid>
      <description>&lt;p&gt;JSON works fine for APIs, but it's inefficient for LLM inputs. Every repeated key, every bracket, every quote consumes tokens. TOON (Token-Oriented Object Notation) reduces token usage by 30-60% while preserving the exact same data structure.&lt;/p&gt;

&lt;p&gt;This guide covers four ways to convert JSON to TOON, from code libraries to desktop apps, so you can pick the right tool for your workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is TOON?
&lt;/h2&gt;

&lt;p&gt;TOON is a data serialization format designed specifically for LLM inputs. It uses YAML-like indentation for nested structures and CSV-style rows for uniform arrays, eliminating redundant syntax while remaining human-readable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JSON (51 tokens):&lt;/strong&gt;&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;"users"&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;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;"Alice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"admin"&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;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;"Bob"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"user"&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;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;strong&gt;TOON (24 tokens):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;users[2]{id,name,role}:
  1,Alice,admin
  2,Bob,user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same data. Half the tokens. The schema is declared once in the header, then each row contains only values—no repeated keys, no brackets, no quotes around simple strings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 1: Code Libraries
&lt;/h2&gt;

&lt;p&gt;Use this when you're building software that sends data to LLMs.&lt;/p&gt;

&lt;p&gt;TOON has official implementations for JavaScript, Python, Java, Julia, and Rust, plus community libraries for 15+ other languages including Go, PHP, Ruby, Swift, Kotlin, C++, Elixir, and R. Check the &lt;a href="https://github.com/toon-format/toon" rel="noopener noreferrer"&gt;official TOON repository&lt;/a&gt; for the full list.&lt;/p&gt;

&lt;p&gt;Here are examples for the two most common languages:&lt;/p&gt;

&lt;h3&gt;
  
  
  JavaScript/TypeScript
&lt;/h3&gt;

&lt;p&gt;Install the official package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @toon-format/toon
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Convert JSON to TOON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;decode&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@toon-format/toon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;users&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="na"&gt;id&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin&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="na"&gt;id&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="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;toon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// users[2]{id,name,role}:&lt;/span&gt;
&lt;span class="c1"&gt;//   1,Alice,admin&lt;/span&gt;
&lt;span class="c1"&gt;//   2,Bob,user&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;restored&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;toon&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Back to JSON&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Python
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;toon-llm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;toon_llm&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ToonSerializer&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;users&lt;/span&gt;&lt;span class="sh"&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Alice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;admin&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bob&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&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="n"&gt;toon_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ToonSerializer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&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;When to use:&lt;/strong&gt; You're building an application that sends data to LLMs and want to convert programmatically before each API call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 2: Command Line
&lt;/h2&gt;

&lt;p&gt;Best for quick one-off conversions, shell scripts, or piping data between tools.&lt;/p&gt;

&lt;p&gt;The official CLI auto-detects format from file extensions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# JSON to TOON&lt;/span&gt;
npx @toon-format/cli data.json &lt;span class="nt"&gt;-o&lt;/span&gt; data.toon

&lt;span class="c"&gt;# TOON to JSON&lt;/span&gt;
npx @toon-format/cli data.toon &lt;span class="nt"&gt;-o&lt;/span&gt; output.json

&lt;span class="c"&gt;# Pipe from stdin&lt;/span&gt;
&lt;span class="nb"&gt;cat &lt;/span&gt;api-response.json | npx @toon-format/cli &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; optimized.toon

&lt;span class="c"&gt;# Show token savings&lt;/span&gt;
npx @toon-format/cli data.json &lt;span class="nt"&gt;--stats&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt; You have JSON files on disk and want to convert them without writing code. Good for scripting and automation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 3: Online Converters
&lt;/h2&gt;

&lt;p&gt;Best for quick tests with non-sensitive data.&lt;/p&gt;

&lt;p&gt;Several browser-based tools exist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://toonformat.dev/playground" rel="noopener noreferrer"&gt;toonformat.dev/playground&lt;/a&gt;&lt;/strong&gt; — Official TOON playground with token comparison&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://toontools.vercel.app/" rel="noopener noreferrer"&gt;toontools.vercel.app&lt;/a&gt;&lt;/strong&gt; — Simple converter interface&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All process data in-browser (client-side JavaScript), so data technically doesn't hit their servers. But you're still loading external scripts, and there's no way to verify what happens with your input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt; Testing TOON syntax with sample data. Avoid for anything containing API keys, user data, or proprietary information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method 4: Desktop Apps (Offline)
&lt;/h2&gt;

&lt;p&gt;Best for sensitive data, air-gapped environments, or developers who want a permanent tool.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://primeutils.com" rel="noopener noreferrer"&gt;PrimeUtils&lt;/a&gt; is a macOS toolkit with 100+ developer utilities, including a TOON converter that works entirely offline. No network calls, no external dependencies—your data never leaves your machine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What sets it apart:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;True offline operation&lt;/strong&gt; — Works without internet. Verify with Little Snitch or a packet sniffer if you're skeptical.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-format support&lt;/strong&gt; — Convert JSON, YAML, XML, or CSV to TOON directly. No need to convert to JSON first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bidirectional&lt;/strong&gt; — TOON back to any supported format with one click.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part of a larger toolkit&lt;/strong&gt; — JWT debugger, Base64 encoder, hash generators, regex tester, and 100+ other utilities in one app.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The workflow is straightforward: select your input format, paste or load your data, click Convert. Output appears instantly with a copy button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When to use:&lt;/strong&gt; You're working with production data, client information, or anything you can't paste into a web form. Also useful if you regularly switch between JSON, YAML, and other formats.&lt;/p&gt;

&lt;p&gt;PrimeUtils is a paid app (one-time purchase), with a demo version available to test core features.&lt;/p&gt;

&lt;h2&gt;
  
  
  When TOON Doesn't Help
&lt;/h2&gt;

&lt;p&gt;TOON isn't universally better than JSON. Skip it when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data is deeply nested with non-uniform structures&lt;/strong&gt; — TOON's efficiency comes from tabular arrays. Complex nested configs may actually use more tokens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Arrays have inconsistent schemas&lt;/strong&gt; — If objects in an array have different fields, TOON can't use its compact row format.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You need pure tabular data&lt;/strong&gt; — For flat tables with no nesting, CSV is 5-10% smaller than TOON.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latency matters more than tokens&lt;/strong&gt; — Serialization adds overhead. For real-time applications, benchmark both formats.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;TOON's sweet spot: uniform arrays of objects with consistent fields across hundreds or thousands of rows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Method&lt;/th&gt;
&lt;th&gt;Best For&lt;/th&gt;
&lt;th&gt;Offline&lt;/th&gt;
&lt;th&gt;Multi-Format&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Code Libraries&lt;/td&gt;
&lt;td&gt;Automated pipelines&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No (JSON only)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CLI&lt;/td&gt;
&lt;td&gt;Scripts, one-off files&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No (JSON only)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Online Tools&lt;/td&gt;
&lt;td&gt;Quick tests&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PrimeUtils&lt;/td&gt;
&lt;td&gt;Sensitive data, daily use&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes (JSON, YAML, XML, CSV)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Converting JSON to TOON is straightforward regardless of which method you choose. The right tool depends on your workflow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building an app? Use the code libraries.&lt;/li&gt;
&lt;li&gt;Scripting? Use the CLI.&lt;/li&gt;
&lt;li&gt;Quick test? Online converters work.&lt;/li&gt;
&lt;li&gt;Sensitive data or multi-format needs? A desktop tool like PrimeUtils keeps everything local.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start with whatever matches your current task. The 30-60% token savings compound quickly when you're making thousands of LLM API calls.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>rag</category>
    </item>
    <item>
      <title>Class loaders in JVM: An Overview</title>
      <dc:creator>Illia Pantsyr</dc:creator>
      <pubDate>Sun, 05 Nov 2023 12:05:17 +0000</pubDate>
      <link>https://dev.to/panilya/class-loaders-in-jvm-an-overview-14da</link>
      <guid>https://dev.to/panilya/class-loaders-in-jvm-an-overview-14da</guid>
      <description>&lt;p&gt;Class loaders are an essential part of the Java Virtual Machine (JVM), but many developers consider them to be mysterious. This article aims to demystify the subject by providing a basic understanding of how class loading works in the JVM.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are classloaders
&lt;/h2&gt;

&lt;p&gt;In the Java Virtual Machine (JVM), classes are loaded dynamically and found through a process called class loading. Class loading is the process of loading a class from its binary representation (usually a .class file) into memory so that it can be executed by the JVM. This is where we need classloaders. Class loaders are used to load .class file into the memory.&lt;/p&gt;

&lt;h2&gt;
  
  
  How classes are loaded in JVM
&lt;/h2&gt;

&lt;p&gt;Classes are loaded in 3 steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creation and Loading step.
First thing that happens is loading a class file using a class loader. There are two kinds of class loaders: the bootstrap class loader supplied by the JVM, and user-defined class loaders. (More details about class loaders are in the next chapter)
Then, instance of &lt;code&gt;java.lang.Class&lt;/code&gt; class is created. What makes the class available to the JVM for further execution &lt;a href="https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-5.html#jvms-5.2" rel="noopener noreferrer"&gt;A detailed step-by-step algorithm can be found in the Java Virtual Machine specification.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Linking step&lt;br&gt;
Before the class is ready for execution, the JVM needs to perform a number of preparatory operations, which include verification and preparation of the class for execution.&lt;br&gt;
Linking steps are following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Bytecode verification.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Verification ensures that the binary representation of a class or interface is structurally correct and is not corrupted, otherwise the class file will not be linked and a VerifyError error will be thrown. Verification can be turned off by the &lt;code&gt;-noverify&lt;/code&gt; option. Turning off the verification can speed up the startup of the JVM, but disabling bytecode verification undermines Java's safety and security guarantees. &lt;a href="https://wiki.sei.cmu.edu/confluence/display/java/ENV04-J.+Do+not+disable+bytecode+verification" rel="noopener noreferrer"&gt;Why not to disable bytecode verification.&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Preparation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Allocate RAM for static fields and initialize them with default values.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Resolution of symbolic links.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Since all references to fields, methods, and other classes are symbolic. JVM, in order to execute the class, you need to translate the references into internal representations.&lt;/p&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Initialization step.&lt;br&gt;&lt;br&gt;
After a class is successfully loaded and linked, it can be initialized. At this stage, the static class initializers or static variable initializers are called, which ensures that static initialization block is executed only once and static variables are initialized correctly.&lt;/p&gt;&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;Also, it is worth remembering that Java implements delayed (or lazy) loading of classes. This means that class loading of reference fields of the loaded class will not be performed until the application explicitly refers to them. In other words, character reference resolution is optional and does not happen by default.&lt;/p&gt;

&lt;h2&gt;
  
  
  Class loader features
&lt;/h2&gt;

&lt;p&gt;Class loaders has three important features that is worth to remember.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Delegation model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When requested to find a class or resource, a class loader will delegate the search for the class or resource to its parent class loader before attempting to find the class or resource itself.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Visibility&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Classes loaded by a parent class loader are visible to its child class loaders, but classes loaded by a child class loader are not visible to its parent class loaders or children.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uniqueness&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Java a class is uniquely identified using &lt;code&gt;ClassLoader + Class&lt;/code&gt; as the same class may be loaded by two different class loaders.&lt;br&gt;
  &lt;code&gt;Class A loaded by ClassLoader A != Class A loaded by ClassLoader B&lt;/code&gt;&lt;br&gt;
  It is helpful for defining different protection and access policies for different classloaders.&lt;/p&gt;

&lt;h2&gt;
  
  
  Class loaders relationship
&lt;/h2&gt;

&lt;p&gt;We should remember that classes in Java are loaded on demand. That is, class is loaded only when is requested to.&lt;/p&gt;

&lt;p&gt;As you know, the entry point of every program written in Java is &lt;code&gt;public static void main(String[] args)&lt;/code&gt; method. Main method is the place where the very first class is loaded. All the subsequently loaded classes are loaded by the classes, which are already loaded and running.&lt;/p&gt;

&lt;p&gt;When a class is requested by the running program, the System class loader searches for it in the application classpath. If the class is not found, the Platform class loader is searched, and if still not found, the Bootstrap class loader is searched.&lt;/p&gt;

&lt;p&gt;If the requested class is found in a parent class loader, it is loaded by that class loader. If not, the System class loader loads the class. If the class has not been loaded before, the class loader loads it into memory and creates a new instance of the Class object that represents the loaded class.&lt;/p&gt;

&lt;p&gt;It is important to note that the class loading hierarchy is hierarchical in nature, with each class loader having a parent class loader. This parent-child relationship ensures that each class loader is responsible for loading only its own classes and delegates the loading of parent classes to its parent class loader.&lt;/p&gt;

&lt;h2&gt;
  
  
  Different types of classloaders
&lt;/h2&gt;

&lt;p&gt;The class loading mechanist in JVM doesn't use only one class loader. Every Java program has at least three class loaders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bootstrap (Primordial) class loader&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the root class loader and is responsible for loading core Java classes such as java.lang.Object and other classes in the Java standard library (also known as the Java Runtime Environment or JRE). It is implemented in native code and is part of the JVM itself. Althrough each class loader has its own &lt;code&gt;ClassLoader&lt;/code&gt; object, there is not such object corresponding to the Bootstrap Class Loader. For example, if you would run this line of code&lt;br&gt;
  &lt;code&gt;String.class.getClassLoader()&lt;/code&gt;, you would get &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extension class loader&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This class loader is responsible for loading classes from the extension directories (such as the jre/lib/ext directory in the JRE installation) and is child of Bootstrap Class Loader. You can also specify the locations of the extension directories via the &lt;code&gt;java.ext.dirs&lt;/code&gt; system property.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System (Application) class loader&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the class loader that loads application-specific classes, usually from the classpath specified when running the Java application. The classpath can include directories, JAR files, and other resources. The classpath can be set using the CLASSPATH environment variable, the -classpath or -cp command-line option. The System/Application Class Loader is also implemented in Java and is a child of the Extension Class Loader.&lt;/p&gt;

&lt;h2&gt;
  
  
  Class loaders and related to them changes over time
&lt;/h2&gt;

&lt;p&gt;In the previous section, we've seen class loaders hierarchy that was in Java until Java 9 revised that.&lt;/p&gt;

&lt;p&gt;New class loaders hierarchy since Java 9 looks like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bootstrap (Primordial) class loader&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the root class loader and is responsible for loading core Java classes such as &lt;code&gt;java.lang.Object&lt;/code&gt; and other classes in the Java standard library (also known as the Java Runtime Environment or JRE). It is implemented in native code and is part of the JVM itself. Althrough each class loader has its own &lt;code&gt;ClassLoader&lt;/code&gt; object, there is not such object corresponding to the Bootstrap class loader and, typically represented as &lt;code&gt;null&lt;/code&gt;, and doesn't have a parent. For example, if you would run this line of code&lt;br&gt;
  &lt;code&gt;String.class.getClassLoader()&lt;/code&gt;, you would get &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Platform class loader (former Extension class loader)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All classes in the Java SE Platform are guaranteed to be visible though the Platform class loader. Just because a class is visible through the platform class loader does not mean the class is actually defined by the platform class loader. Some classes in the Java SE Platform are defined by the platform class loader while others are defined by the Bootstrap class loader. Applications should not depend on which class loader defines which platform class.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;System (Application) class loader&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the class loader that loads application-specific classes, usually from the classpath specified when running the Java application. The classpath can include directories, JAR files, and other resources. The classpath can be set using the CLASSPATH environment variable, the -classpath or -cp command-line option. The System/Application class loader is also implemented in Java and is a child of the Extension class loader.&lt;/p&gt;

&lt;p&gt;There are even more changes that were introduced in Java 9 which are related to class loaders, namely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Application class loader is no longer an instance of &lt;code&gt;URLClassLoader&lt;/code&gt; but, rather, of an internal class. Now, there are &lt;code&gt;ClassLoaders&lt;/code&gt; class that contains in itself implementation of 3 built-in class loaders. Such as:

&lt;ol&gt;
&lt;li&gt;BootClassLoader&lt;/li&gt;
&lt;li&gt;PlatformClassLoader&lt;/li&gt;
&lt;li&gt;AppClassLoader

&lt;ul&gt;
&lt;li&gt;However, bootstrap class loader should be used via &lt;code&gt;BootLoader&lt;/code&gt; class and not via &lt;code&gt;ClassLoaders&lt;/code&gt; class.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;/li&gt;

&lt;li&gt;The Extension class loader has been renamed to Platform class loader.
Substantial difference between Java 8 Extension class loader and Java 9 Platform class loader is that Platform class loader is no longer instance of &lt;code&gt;URLClassLoader&lt;/code&gt;.
But for the most part, the platform class loader is the equivalent of what used to known as the Extension class loader. One motivation for renaming it, is that extension mechanism has been removed, which we will discuss in the next paragraph.&lt;/li&gt;

&lt;li&gt;Removed Extension Mechanism
In releases before Java 9, the extension mechanism allowed the runtime environment to find and load extension classes without explicitly mentioning them on the classpath. However, in JDK 9, this mechanism has been removed. To use extension classes, ensure that their JAR files are included in the classpath.&lt;/li&gt;

&lt;li&gt;Removed rt.jar and tools.jar

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;rt.jar&lt;/code&gt; contains all of the compiled class files for the base Java Runtime environment.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;tools.jar&lt;/code&gt; contains all tools that are needed by a JDK but not a JRE (javac, javadoc, javap).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-5.html" rel="noopener noreferrer"&gt;https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-5.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.artima.com/insidejvm/ed2/securityP.html" rel="noopener noreferrer"&gt;https://www.artima.com/insidejvm/ed2/securityP.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://blogs.oracle.com/javamagazine/post/how-the-jvm-locates-loads-and-runs-libraries" rel="noopener noreferrer"&gt;https://blogs.oracle.com/javamagazine/post/how-the-jvm-locates-loads-and-runs-libraries&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.oracle.com/javase/9/docs/api/java/lang/ClassLoader.html" rel="noopener noreferrer"&gt;https://docs.oracle.com/javase/9/docs/api/java/lang/ClassLoader.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>jvm</category>
      <category>java</category>
    </item>
    <item>
      <title>Datafaker 2.0</title>
      <dc:creator>Illia Pantsyr</dc:creator>
      <pubDate>Sun, 05 Nov 2023 12:01:34 +0000</pubDate>
      <link>https://dev.to/panilya/datafaker-20-23fi</link>
      <guid>https://dev.to/panilya/datafaker-20-23fi</guid>
      <description>&lt;p&gt;One of the major changes in Datafaker 2.0 is the requirement for Java version 17 as a minimum, similar to popular frameworks such as Spring Boot 3.0. This release of Datafaker brings significant improvements to the library's performance, support of Java Records, capability to generate larger amounts of test data, and much more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Schemas and transformers
&lt;/h2&gt;

&lt;p&gt;The most common use case for Datafaker is to generate random readable values in Java, such as firstnames, quotes or other values. &lt;/p&gt;

&lt;p&gt;But what if you need to generate data in some other format, such as JSON or CSV?&lt;br&gt;
For this purpose, Datafaker has a Schema and Transformer concept which work hand in hand and should therefore be used together.&lt;/p&gt;

&lt;p&gt;Let's take a look at what this Schema and Transformer are and what role they play.&lt;/p&gt;

&lt;p&gt;A Schema is a set of rules that describe what needs to be done to convert data from a Datafaker format to one of the supported formats. One of the main advantages of a schema is that the same schema can be used to convert to different formats.&lt;/p&gt;

&lt;p&gt;In Datafaker, each format has its own Transformer implementation. At the time of writing, Datafaker supports 6 formats, which means there are also 6 Transformer implementations, namely:&lt;br&gt;
 ⁃ CSV (CsvTransformer)&lt;br&gt;
 ⁃ JSON (JsonTrasformer)&lt;br&gt;
 ⁃ SQL (SqlTransformer)&lt;br&gt;
 ⁃ YAML (YamlTransformer)&lt;br&gt;
 ⁃ XML (XmlTransformer)&lt;br&gt;
 ⁃ Java Object (JavaObjectTransformer)&lt;/p&gt;

&lt;p&gt;Let's take a closer look at one of the formats, in this case, the CSV format.&lt;/p&gt;
&lt;h3&gt;
  
  
  Generating CSV files
&lt;/h3&gt;

&lt;p&gt;When working with CSV files, there may be times when you need to create CSV files with data, for example for testing purposes. Manually entering data into a CSV file can be a tedious and time-consuming process. Instead of wasting time and effort on manual data entry, you can use a tool like Datafaker to quickly generate as much fake data as you need in a CSV format. Datafaker allows you to specify the number of rows and columns you need, and generate randomized data that can be easily exported to a CSV file. This can be especially useful when working with large datasets or when testing and prototyping your applications.&lt;/p&gt;

&lt;p&gt;Let's look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Faker&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Faker&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Locale&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;GERMANY&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Datafaker supports any locale from the Locale package&lt;/span&gt;
&lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt; &lt;span class="c1"&gt;// Define a schema, which we can use in any Transformer&lt;/span&gt;
    &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"firstName"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;()),&lt;/span&gt;
    &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"lastName"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;()),&lt;/span&gt;
    &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"phoneNumber"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;phoneNumber&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;phoneNumberInternational&lt;/span&gt;&lt;span class="o"&gt;()));&lt;/span&gt;

&lt;span class="nc"&gt;CsvTransformer&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;csvTransformer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CsvTransformer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;builder&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Instantiate CsvTransformer using the appropriate builder.&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;csvTransformer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;generate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// This is where the magic happens. Call the `generate` method on the transformer with your schema plus the number of records to get the result as a string.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A possible result that can be obtained by executing the code above can be found below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"firstName";"lastName";"phoneNumber"
"Jannik";"Ripken";"+49 9924 780126"
"Frederike";"Birkemeyer";"+49 2933 945975"
"Michelle";"Steuk";"+49 7033 814683"
"Ellen";"Semisch";"+49 9537 991422"
"Oskar";"Habel";"+49 3626 169891"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CsvTransformer builder also gives you several parameters to use, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;quote()&lt;/code&gt;, in case you want to change the default(&lt;code&gt;"&lt;/code&gt;) quote.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;separator()&lt;/code&gt;, the character which delimits columns in rows.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;header()&lt;/code&gt; boolean parameter which toggles the generation of the header in the resulted CSV.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All other 5 formats work on the same principle, except for the Java Object format.&lt;/p&gt;

&lt;p&gt;Let's see what is so special about this Java Object transformation.&lt;/p&gt;

&lt;h3&gt;
  
  
  JavaObjectTransformer
&lt;/h3&gt;

&lt;p&gt;JavaObjectTransformer is available since version 1.8.0 of Datafaker. This was further enhanced in Datafaker 2.0 by providing support for Java Records in the JavaObjectTransformer.&lt;/p&gt;

&lt;p&gt;In total, we have two ways to work with the JavaObjectTransformer:&lt;/p&gt;

&lt;p&gt;1) Use JavaObjectTransformer and Schema.&lt;br&gt;
2) Use a predefined Schema.&lt;/p&gt;
&lt;h4&gt;
  
  
  JavaObjectTransformer with Transformer and Schema pair
&lt;/h4&gt;

&lt;p&gt;Let's take a closer look at each option. The first way to use it is through the familiar Transformer and Schema pair. Let's look at a practical example:&lt;/p&gt;

&lt;p&gt;Note that we use Java 17 and Datafaker 2.0. Therefore, we will create a &lt;code&gt;Client&lt;/code&gt; Java Record with 3 properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="nf"&gt;Client&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;phoneNumber&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we need to provide the Schema for our class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Faker&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Faker&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;JavaObjectTransformer&lt;/span&gt; &lt;span class="n"&gt;jTransformer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;JavaObjectTransformer&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;schema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"firstName"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;()),&lt;/span&gt;
    &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"lastName"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;()),&lt;/span&gt;
    &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"phoneNumber"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;phoneNumber&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;phoneNumberInternational&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jTransformer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of our program will be as follows:&lt;br&gt;
&lt;code&gt;Client{firstName='Elton', lastName='Conroy', phoneNumber='+1 808-239-0480'}&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  JavaObjectTransformer with Transformer and predefined Schema
&lt;/h4&gt;

&lt;p&gt;Let's take a look at the second use case, namely, populating Java objects with a predefined schema.&lt;br&gt;
The essence of this approach is to override the schema and use it without explicitly specifying it every time.&lt;/p&gt;

&lt;p&gt;Let's move on to a practical example:&lt;/p&gt;

&lt;p&gt;First of all, we need to define our schema for our model. It is defined as follows and, on my machine, located in the &lt;code&gt;com.datafaker&lt;/code&gt; package in the &lt;code&gt;DatafakerSchema&lt;/code&gt; class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;defaultSchema&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Faker&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Locale&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;UK&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;RandomService&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Random&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;)));&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"firstName"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;()),&lt;/span&gt;
        &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"lastName"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;()),&lt;/span&gt;
        &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"phoneNumber"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;phoneNumber&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;phoneNumberInternational&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
    &lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you should provide a class to be used as a template for generated objects. This class should be annotated with the &lt;code&gt;@FakeForSchema&lt;/code&gt; annotation with the path to the schema method as a value.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: If the default schema and the class template are in the same class, you can omit the full path to the method and use only the method name.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@FakeForSchema&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"com.datafaker.DatafakerSchema#defaultSchema"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="n"&gt;record&lt;/span&gt; &lt;span class="nf"&gt;Client&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;phoneNumber&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you can use &lt;code&gt;net.datafaker.providers.base.BaseFaker.populate(java.lang.Class&amp;lt;T&amp;gt;)&lt;/code&gt; to populate the object with the default predefined schema.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Client&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BaseFaker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;populate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, you can use &lt;code&gt;net.datafaker.providers.base.BaseFaker.populate(java.lang.Class&amp;lt;T&amp;gt;, net.datafaker.schema.Schema&amp;lt;java.lang.Object, ?&amp;gt;)&lt;/code&gt; to populate the object with a custom schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Client&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BaseFaker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;populate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;of&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"firstName"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="o"&gt;()),&lt;/span&gt;
    &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"lastName"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="o"&gt;()),&lt;/span&gt;
    &lt;span class="n"&gt;field&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"phoneNumber"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;phoneNumber&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;phoneNumberInternational&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of both &lt;code&gt;populate&lt;/code&gt; methods will be the same:&lt;br&gt;
&lt;code&gt;Client{firstName='Darrel', lastName='Bogisich', phoneNumber='+44 161-444-6889'}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you want to know more, you can find more information about Schema and Transformers in the official documentation of &lt;a href="https://www.datafaker.net/documentation/schemas/" rel="noopener noreferrer"&gt;Datafaker&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Sequences
&lt;/h2&gt;

&lt;p&gt;Sequences are a very powerful but undervalued feature of Datafaker. Imagine a situation where you need just a &lt;code&gt;java.util.List&lt;/code&gt; of random values or you need to have an infinite stream of random data. In such situations, Datafaker sequences are a great fit. But before you start using it, it's good to know the details of sequences and their types, and that's what we're going to do.&lt;/p&gt;

&lt;p&gt;Datafaker supports two types of fake sequences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FakeCollection&lt;/li&gt;
&lt;li&gt;FakeStream&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;FakeCollection is used to generate an in-memory list of fake values. Let's take a look at a practical example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Faker&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Faker&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;collection&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;fullName&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
        &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;len&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;generate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code example will generate a List of fake values, where each element will either be a full name or a city, with a length between 2 and 6 elements. This is a possible result of the code above:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[Pete Nienow, Erik Kub, New Jerrie, Tempie Erdman]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;FakeStream is used to generate a &lt;code&gt;java.util.stream.Stream&lt;/code&gt; of fake values. FakeStream is similar to FakeCollection, however, there are some important differences. For example, FakeStream can be infinite and the result of the FakeStream is a Stream object with generated values instead of a collection.&lt;/p&gt;

&lt;p&gt;Imagine you need to model a constant stream of data. For example, the temperature from an IoT temperature sensor. In this case, FakeStream will be the right choice. Let's see how to write this in code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Faker&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Faker&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;objects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;random&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;nextDouble&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;generate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;println&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code will generate a constant stream of doubles between 20 and 22. However, it's also possible to specify the length of the stream via the &lt;code&gt;len(int minLength, int maxLength)&lt;/code&gt; or &lt;code&gt;len(int length)&lt;/code&gt; parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Faker&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Faker&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;Stream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;objects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;faker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;random&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;nextDouble&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;len&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;generate&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;forEach&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;println&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The possible result may be: &lt;code&gt;21.663129306577716&lt;br&gt;
20.228104917791825&lt;br&gt;
20.559417738876828&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, Datafaker 2.0 is a significant upgrade to an already impressive data generation library. With its diverse data generation options and improved scalability, Datafaker 2.0 is an essential tool for developers looking to generate realistic and diverse data for testing and development purposes. For more information, head over to &lt;a href="https://www.datafaker.net/documentation/getting-started/" rel="noopener noreferrer"&gt;Datafaker documentation.&lt;/a&gt; and don't forget to star &lt;a href="https://github.com/datafaker-net/datafaker" rel="noopener noreferrer"&gt;Datafaker&lt;/a&gt; on the GitHub!&lt;/p&gt;

</description>
      <category>java</category>
      <category>datafaker</category>
      <category>opensource</category>
      <category>fakedata</category>
    </item>
  </channel>
</rss>
