# Getting JSON output

AiBrow supports defining grammar on the `LanguageModel` API. This allows you to constrain the output as needed. [Grammar support](https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md) is provided by `llama-cpp` .

{% hint style="info" %}
Learn more about [how to use Grammar](https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md)
{% endhint %}

Constraining the output allows you to confidently parse the output and work on it. This is an excellent way to chain prompts together and make full use of the language model. Here's how you can extract some data from some text as a JSON structure...

```javascript
import AI from '@aibrow/web'

const session = await AI.LanguageModel.create()
// We want to extract some data from this text
const prompt = "Extract data from the following text: John Doe is an innovative software developer with a passion for creating intuitive user experiences. Based in the heart of England, John has spent the past decade refining his craft, working with both startups and established tech companies. His deep commitment to quality and creativity is evident in the numerous award-winning apps he has developed, which continue to enrich the digital lives of users worldwide. Beyond his technical skills, John is admired for his collaborative spirit and mentorship, always eager to share his knowledge and inspire the next generation of tech enthusiasts."

// Define the type of object we want returned
const grammar = {
  "type": "object",
  "properties": {
    "first_name": {
      "type": "string"
    },
    "last_name": {
      "type": "string"
    },
    "country": {
      "type": "string"
    }
  }
}

// Prompt the model
const stream = await session.promptStreaming(prompt, { responseConstraint: grammar })
let output = ''
for await (const chunk of stream) {
  console.log(chunk)
  output += chunk
}

console.log(JSON.parse(output))
// { "first_name": "John", "last_name": "Doe", "country": "England" }
```


---

# 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://docs.aibrow.ai/examples/getting-json-output.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.
