jtyper
v1.0.0
Published
Extract complete data structure template from JSON, merging arrays to find the most complete schema
Maintainers
Readme
jtyper
Extract complete data structure template from JSON files. Recursively analyzes nested objects and arrays, merging all elements to produce the most complete schema.
Install
npm install -g jtyperUsage
CLI
# Analyze entire file
jtyper data.json
# Extract specific path
jtyper data.json users.profileProgrammatic
const { extract, getByPath } = require('jtyper');
const data = {
users: [
{ name: "Alice", age: 30 },
{ name: "Bob", meta: { active: true } }
]
};
const structure = extract(data);
// {
// "users": [{
// "name": "string",
// "age": "number",
// "meta": { "active": "boolean" }
// }]
// }
const usersStructure = getByPath(structure, 'users');
// [{ "name": "string", "age": "number", "meta": { "active": "boolean" } }]How It Works
- Replaces primitive values with type names (
string,number,boolean,null) - Merges all array elements to find the most complete structure
- Empty arrays
[]are overwritten by non-empty ones nullvalues are overwritten by objects
Example
Input:
{
"items": [
{ "id": 1, "tags": [] },
{ "id": 2, "tags": ["a"], "meta": { "views": 100 } }
]
}Output:
{
"items": [{
"id": "number",
"tags": ["string"],
"meta": { "views": "number" }
}]
}License
MIT
