
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@synstack/json
Advanced tools
Schema-safe and type-safe JSON serialization and deserialization
[!WARNING] This package is included in the @synstack/synscript package. It is not recommended to install both packages at the same time.
[!NOTE] This package is accessible through @synstack/fs for convenience.
When you need to work with JSON data in a type-safe way, this package provides simple, strongly-typed functions:
import { serialize, deserialize } from "@synstack/json";
import { z } from "zod";
// Define a schema for type safety
const userSchema = z.object({
name: z.string(),
age: z.number(),
});
// Serialize data with schema validation
const jsonString = serialize(
{ name: "John", age: 30 },
{ schema: userSchema, pretty: true },
);
// Deserialize with type inference
const user = deserialize(jsonString, { schema: userSchema });
console.log(user.name); // Type-safe access
// Handle invalid JSON gracefully
try {
deserialize("invalid json");
} catch (error) {
if (error instanceof JsonParseException) {
console.error("Failed to parse JSON:", error.message);
}
}
# Using npm
npm install @synstack/json
# Using yarn
yarn add @synstack/json
# Using pnpm
pnpm add @synstack/json
Convert JavaScript objects to JSON strings with optional pretty printing:
import { serialize } from "@synstack/json";
// Basic serialization
const json = serialize({ hello: "world" });
// Pretty printing
const prettyJson = serialize({ hello: "world" }, { pretty: true });
console.log(prettyJson);
// {
// "hello": "world"
// }
Parse JSON strings with TypeScript type inference:
import { deserialize } from "@synstack/json";
// Basic deserialization
const data = deserialize<{ count: number }>('{"count": 42}');
console.log(data.count); // TypeScript knows this is a number
// Handle parsing errors
try {
deserialize('{"invalid": json}');
} catch (error) {
console.error("Invalid JSON:", error.message);
}
Use Zod schemas for runtime type checking:
import { serialize, deserialize } from "@synstack/json";
import { z } from "zod";
// Define a schema
const configSchema = z.object({
port: z.number(),
host: z.string(),
debug: z.boolean(),
});
// Validate during serialization
const jsonString = serialize(
{ port: 3000, host: "localhost", debug: true },
{ schema: configSchema },
);
// Validate during deserialization
const config = deserialize(jsonString, {
schema: configSchema,
});
// config has type { port: number; host: string; debug: boolean }
FAQs
Schema-safe and type-safe JSON serialization and deserialization
The npm package @synstack/json receives a total of 10 weekly downloads. As such, @synstack/json popularity was classified as not popular.
We found that @synstack/json demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.