<?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: Quang Nguyen</title>
    <description>The latest articles on DEV Community by Quang Nguyen (@quangnguyenvn).</description>
    <link>https://dev.to/quangnguyenvn</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%2F2643268%2Fa46fc7aa-dc63-4322-8208-7d4d93156477.jpeg</url>
      <title>DEV Community: Quang Nguyen</title>
      <link>https://dev.to/quangnguyenvn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/quangnguyenvn"/>
    <language>en</language>
    <item>
      <title>JSON0 - Speed Meets Simplicity</title>
      <dc:creator>Quang Nguyen</dc:creator>
      <pubDate>Sun, 29 Jun 2025 09:03:56 +0000</pubDate>
      <link>https://dev.to/quangnguyenvn/json0-speed-meets-simplicity-c2g</link>
      <guid>https://dev.to/quangnguyenvn/json0-speed-meets-simplicity-c2g</guid>
      <description>&lt;h2&gt;
  
  
  I. JSON in Financial Software Systems
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Choosing a Message Format&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While developing a financial software system, our team needed to choose an effective internal messaging format for communication between different modules. After evaluating several options, JSON emerged as a compelling choice due to its multiple advantages:&lt;br&gt;
• Self-descriptive and Flexible: JSON provides a clear, transparent, and human-readable structure that can represent complex business logic. This minimizes debugging time, especially compared to binary formats.&lt;br&gt;
• Easy Conversion from FIX: Messages received by our server are in the FIX protocol, which can be easily converted to JSON.&lt;br&gt;
• Wide Adoption: JSON is ubiquitous. Third-party systems can easily integrate with ours using standard JSON formats, eliminating the need for lengthy documentation or complex onboarding.&lt;br&gt;
• Ease of Use: JSON is simple to produce, parse, and validate. Numerous tools support its verification, facilitating integration and error identification during development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance Considerations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Despite its strengths, JSON has known performance limitations, particularly in high-throughput environments. To ensure suitability, we conducted performance tests focusing on JSON generation, as this is the primary workload for our servers.&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%2F25gxsz0ck56t7p526dk5.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%2F25gxsz0ck56t7p526dk5.png" alt="Image description" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;• Hardware: Tests were conducted on a modest system running Linux 2.6 with an AMD Ryzen 7 1700 Eight-Core CPU.&lt;br&gt;
• JVM Configuration: Started with -Xms1500M.&lt;br&gt;
• Library: &lt;a href="https://github.com/fangyidong/json-simple" rel="noopener noreferrer"&gt;JSON-simple&lt;/a&gt; was used to generate JSON objects.&lt;br&gt;
• Source Code: &lt;a href="https://github.com/quangnguyenvn/JSON0/blob/main/perf_test/java/server_scripts/JSON0Perf.java" rel="noopener noreferrer"&gt;JSONSimplePerf.java&lt;/a&gt;&lt;br&gt;
• Test Details: The method produceUsingJSONSimple was executed repeatedly to generate ~1 million JSON objects. Elapsed time was logged to assess consistency. The first run (1,000 objects) served as a warm-up.&lt;br&gt;
• Output: &lt;a href="https://github.com/quangnguyenvn/JSON0/blob/main/perf_test/java/server_scripts/outputs/JSONSimpleOutput.txt" rel="noopener noreferrer"&gt;JSONSimpleOutput.txt&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Results&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The system consistently produced 1 million JSON objects in around 3 seconds. While sufficient for many real-world scenarios, our system's requirement to handle over 100,000 messages per second highlighted performance concerns. Message complexity in our production system also exceeds that of the test cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Opportunities for Optimization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;From analyzing the JSON-simple implementation, we identified potential inefficiencies:&lt;br&gt;
• Map-Based Design: Each insertion invokes a hash function, which is unnecessary when we only generate (not retrieve) data.&lt;br&gt;
• Limited Object Reuse: Repeated object creation triggers garbage collection (GC), which is undesirable in real-time systems.&lt;br&gt;
• Indirect Byte Conversion: JSON-simple lacks a direct conversion method to byte arrays; strings must first be created, introducing overhead.&lt;/p&gt;
&lt;h2&gt;
  
  
  II. Enter JSON0: A High-Performance Alternative
&lt;/h2&gt;

&lt;p&gt;To address these limitations, we tested the same scenarios using JSON0, a custom-built JSON library optimized for speed.&lt;br&gt;
• Key Enhancements:&lt;br&gt;
o   Direct creation of child objects via createJSON() and createJSONArray().&lt;br&gt;
o   Support for object reuse using reset().&lt;br&gt;
o   Efficient toBytes() method to convert JSON directly into byte arrays.&lt;br&gt;
• Results: &lt;a href="https://github.com/quangnguyenvn/JSON0/blob/main/perf_test/java/server_scripts/outputs/JSON0Output.txt" rel="noopener noreferrer"&gt;JSON0Output.txt&lt;/a&gt;&lt;br&gt;
JSON0 reduced the time to generate 1 million objects to approximately 1.35 seconds, more than twice as fast as JSON-simple.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Although performance bottlenecks are less common today due to faster hardware, JSON0 demonstrates that software-level optimizations can significantly improve throughput without relying on hardware upgrades. Moreover, the API remains developer-friendly and intuitive.&lt;/p&gt;
&lt;h2&gt;
  
  
  III. Installation &amp;amp; Usage
&lt;/h2&gt;

&lt;p&gt;JSON0 is available on Maven Central:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;&lt;br&gt;
    &amp;lt;groupId&amp;gt;io.github.kwangng&amp;lt;/groupId&amp;gt;&lt;br&gt;
    &amp;lt;artifactId&amp;gt;JSON0&amp;lt;/artifactId&amp;gt;&lt;br&gt;
    &amp;lt;version&amp;gt;1.0.8&amp;lt;/version&amp;gt;&lt;br&gt;
&amp;lt;/dependency&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Example&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;JSON0 json = new JSON0();&lt;br&gt;
json.reset();&lt;br&gt;
json.put("Town", "Hoi An Town");&lt;br&gt;
json.put("DayLength", 3);&lt;br&gt;
json.put("Vehicles", "Taxi or Bike");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;JSON0 visits = json.createJSON("MustVisits");&lt;br&gt;
visits.put("Morning", "Tra Que Vegetable Village");&lt;br&gt;
visits.put("Afternoon", "The Japanese Bridge");&lt;br&gt;
visits.put("Evening", "An Bang Beach");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;JSON0 mustTry = json.createJSONArray("MustTries");&lt;br&gt;
JSON0 foods = mustTry.createJSON("Foods");&lt;br&gt;
foods.put("Food1", "Banh Mi, Banh Xeo");&lt;br&gt;
foods.put("Food2", "Com Ga Hoi An");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;JSON0 drinks = mustTry.createJSON("Drinks");&lt;br&gt;
drinks.put("Drink1", "Cafe Sua Da");&lt;br&gt;
drinks.put("Drink2", "Mot Hoi An");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Methods&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;Create root JSON:                  new JSON0()
Add key-value pair:                put(String key, Object value)
Get value:                         get(String key)
Create child JSON:                 createJSON(String key)
Create array of JSON objects:          createJSONArray(String key)
Reset object for reuse:            reset()
Convert to string:                 toString()
Convert to byte array:                 toBytes()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JSON0 GitHub Repository: &lt;a href="https://github.com/quangnguyenvn/JSON0" rel="noopener noreferrer"&gt;https://github.com/quangnguyenvn/JSON0&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>opensource</category>
      <category>stripe</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
