# Quick start

Modélico's goal is to parse JSON strings like

```javascript
{
  "name": "Robbie"
}
```

into JavaScript custom objects so that we can do things like this:

```javascript
const myPet = M.fromJSON(Animal, petJson)

myPet.speak() // => 'my name is Robbie!'
```

Here is how `Animal` would look like:

```javascript
const M = require('modelico')

class Animal extends M.createModel(m => ({
  name: m.string()
})) {
  speak() {
    const name = this.name()

    return (name === '') ? `I don't have a name` : `My name is ${name}!`
  }
}
```

The name is required by default. See the [Optional / null values page](/basics/optional_values.md) to change the default behaviour.

With a bit more effort, we can have a detailed JSON schema, with the benefits that they bring, eg. integration with [JSON Shema Faker](https://github.com/json-schema-faker/json-schema-faker) to generate random data.

```javascript
const M = require('modelico')
const Ajv = require('ajv')

class Animal extends M.createAjvModel(new Ajv(), m => ({
  name: m.string({minLength: 1})
})) {
  speak () {
    const name = this.name()

    // the validation is only applied when reviving, not when creating new
    // instances directly (ie. new Animal({name: ''})) does not throw
    return (name === '') ? `I don't have a name` : `My name is ${name}!`
  }
}
```

Now when can do the following to get the schema:

```javascript
M.getSchema(Animal);
// =>
// {
//   "type": "object",
//   "properties": {
//     "name": {
//       "$ref": "#/definitions/2"
//     }
//   },
//   "required": ["name"],
//   "definitions": {
//     "2": {
//       "type": "string",
//       "minLength": 1
//     }
//   }
// }
```

See the [nested types example](/quickstart/nested_types_example.md) to learn more.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://modelico.javiercejudo.com/quickstart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
