Getting Started
Installation
Install Morphio using npm:
npm install @rpethani/morphio
Or using yarn:
yarn add @rpethani/morphio
Basic Usage
Morphio provides two ways to define your schema:
- Using decorators (recommended)
- Using schema objects
Using Decorators
import { MorphProp, MorphSchema } from '@rpethani/morphio';
@MorphSchema()
class User {
@MorphProp()
name: string;
@MorphProp()
age: number;
}
const json = '{"name": "John Doe", "age": 30}';
const user = deserialize(json, User);
console.log(user.name); // "John Doe"
console.log(user.age); // 30
Using Schema Objects
import { morphioSchema, deserialize } from '@rpethani/morphio';
const userSchema = morphioSchema({
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' },
},
});
const json = '{"name": "John Doe", "age": 30}';
const user = deserialize(json, userSchema);
console.log(user.name); // "John Doe"
console.log(user.age); // 30
Next Steps
For more examples and detailed API documentation, check out:
- Examples - Various examples showing different use cases
- API Reference - Detailed API documentation