DOCUMENTATION
MIDDLEWARES
Parse Data
Parse
JSON

Parsing JSON Body

The Parse Data middleware parses JSON data from request bodies and converts it into a JavaScript object.

Example

Client-side:

fetch("/data", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ count: "10", active: "true" }),
});

Server-side:

import v from "vkrun";
 
const vkrun = v.App();
 
vkrun.post(
  "/data",
  (
    request: v.Request<{
      body: {
        count: number;
        active: boolean;
      };
    }>,
    response: v.Response
  ) => {
    console.log(request.body);
    // Output: { count: 10, active: true }
    response.status(200).end();
  }
);

In this example:

  • "10" is converted to a number.
  • "true" is converted to a boolean.
Copyright © 2024 - 2025 MIT by Mario Elvio