Urgent.News

What's breaking now, across thousands of outlets.

Tech

Your JSON is valid and your invoice is wrong

Imagine a perfectly reasonable backend refactor. client.name becomes customer.legalName . The new shape is clearer. The JSON parses. The application tests are green. Then someone opens an invoice. Beautiful margins. Correct logo. No customer. The document has successfully generated an invoice addressed to absolutely nobody. This is an illustrative failure in a loosely checked integration, but the…

A JSON-to-PDF API is being developed called Bitavu, which converts JSON data into PDF documents. The refactor from client.name to customer.legalName in the backend seems reasonable, as the JSON parses and the application tests pass. However, when generating an invoice, the customer field is missing, resulting in an invoice addressed to nobody.

This situation highlights that valid JSON alone doesn't guarantee the correctness of a document. The integration between incoming data and the saved document template needs to be more robust. A simple check for valid JSON doesn't provide enough information about the document's accuracy.

To improve the situation, a guard function can be implemented to check for required fields like a client name. If the field is missing or empty, an error can be thrown. This approach provides a more specific integration change to review before sending an invoice.

However, even with a guard function, there can be cases where the input contains correct data types but still maps incorrectly to the intended fields. For example, if both billing and shipping names are present, it's unclear which one should be used for the invoice's Bill to field. This issue cannot be resolved by a structural validator, as it can only check for the existence of a string at a declared path.

To address this problem, it's essential to treat field mappings like code changes and review them carefully. Before adopting a mapping, ask whether it represents the intended business entity. Use synthetic examples with different combinations of data to test the mappings thoroughly.

Bitavu reports schema mismatches with a 422 SCHEMA_DRIFT status code, allowing developers to review the transformation and potentially save a mapping for targeted use in specific template revisions. However, even with this mechanism, a well-defined template contract and a person who understands the meaning of the fields are crucial for ensuring the document's correctness. Ultimately, a green check for valid JSON is not enough to guarantee a correct document.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

I built a world history map where every ruler links to a source

Most history maps show the borders. I wanted one that also says who was in charge, and where that claim came from. You drag a year slider from 1000 BC to today, the borders move, and you can click any…

  • Map identifies rulers and sources for each region from 1000 BC to present
  • Each ruler and claim linked to source URL and quote in code
  • Static map generated beforehand, minimal loading via single TopoJSON per year

How to Compress a Video Without Uploading It (Free, Right in Your Browser)

You filmed a 90 second clip on your phone and it is 180 MB. Your email limit is 25 MB, the chat app will squash it into mush, and the class portal says "file too large".

  • Compress videos in browser without uploading, using H.264 codec
  • Adjust quality (CRF), resolution, and frame rate to reduce size
  • OpenFile toolkit runs ffmpeg in browser via WebAssembly for compression

Building an EV-vs-petrol cost model: total cost of ownership in the browser

An electric car that costs $10,000 more than its petrol equivalent breaks even after 8.6 years at 12,000 miles a year — and never breaks even at all if you charge it mostly at public fast chargers.

  • EV costing $10,000 more than petrol car breaks even after 8.6 years with 12,000 miles/year usage
  • Model calculates annual cost of each car type using miles, fuel price, and maintenance
  • EV cheaper to fuel due to lower fuel consumption per mile compared to petrol cars

More from Tuesday 3 November →