> For the complete documentation index, see [llms.txt](https://gdgaddis.gitbook.io/mobile-development-reference-tce-c01/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gdgaddis.gitbook.io/mobile-development-reference-tce-c01/products-feature/creating-models/introduction-to-json-annotations.md).

# Introduction to JSON annotations

### Installing and Using json\_serializable and json\_annotation packages

Add this to your package's pubspec.yaml file:

```dart
# pubspec.yaml
dependencies:
  json_annotation: ^4.0.0

dev_dependencies:
  build_runner:
  json_serializable 4.0.2
```

You can then install packages from the command line:

```bash
$ dart pub get
```

{% hint style="info" %}
Alternatively, your editor might support `dart pub get`. Check the docs for your editor to learn more.
{% endhint %}

#### Example

Now you can use it in your Dart code by importing it like this:

```bash
import 'package:json_annotation/json_annotation.dart';

part 'my_model.g.dart';
```

{% hint style="info" %}
Note that the line part`my_demo.g.dart`will give you a warning, because the file is not created yet
{% endhint %}

Write the following code

```dart
import 'package:json_annotation/json_annotation.dart';

part 'my_model.g.dart';

@freezed
class Person with _$Person {
  const factory Person({
    @required String firstName,
    @required String lastName,
  }) = _Person;

  factory Person.fromJson(Map<String, dynamic> json) =>
      _$PersonFromJson(json);
}
```

To generate the code type the following command

```dart
$ flutter pub run build_runner build
```

#### Ignore lint warnings on generated files

It is likely that the code generated by Json\_Serializer will cause your linter to report warnings.

The solution to this problem is to tell the linter to ignore generated files, by modifying your `analysis_options.yaml`:

```dart
analyzer:
  exclude:
    - "**/*.g.dart"
```
