شروع کار
اسکریپت را دریافت و در Node.js 22 روی یک فایل JSON محلی اجرا کن. نتیجه ساختار ورودی را بهاختصار توضیح میدهد.
node summary.mjs data.json سازگاری و بازبینی
از دادهٔ ساختگی استفاده کن و پیش از تغییر نمونه، عملکردش را در ابزار خودت بررسی کن.
فایلهای منبع
محتوای اصلی را بررسی کن و هر فایل را جداگانه دریافت کن.
import { readFile } from "node:fs/promises";
const filename = process.argv[2];
if (!filename) {
console.error("Usage: node summary.mjs data.json");
process.exitCode = 1;
} else {
try {
const data = JSON.parse(await readFile(filename, "utf8"));
const type = Array.isArray(data) ? "array" : data === null ? "null" : typeof data;
const result = { type };
if (type === "array") result.length = data.length;
if (type === "object") result.keys = Object.keys(data);
console.log(JSON.stringify(result, null, 2));
} catch (error) {
console.error(error.message);
process.exitCode = 1;
}
}
JSON Summary Utility
Run with Node.js 22: node summary.mjs data.json. The script prints field names or the array length.
با Node.js 22 دستور را روی یک فایل محلی اجرا کن. ابزار نام فیلدها یا طول آرایه را چاپ میکند.
MIT · Betavan demo.
مارکداون خام
# JSON Summary Utility
Run with Node.js 22: node summary.mjs data.json. The script prints field names or the array length.
با Node.js 22 دستور را روی یک فایل محلی اجرا کن. ابزار نام فیلدها یا طول آرایه را چاپ میکند.
MIT · Betavan demo.