Skip to content

Commit 79bba66

Browse files
author
Davide Caroselli
committed
Improve README.md readability
1 parent 5a2e9cd commit 79bba66

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

README.md

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
[download-url]: https://npmjs.org/package/jsonthis
1313

14-
Jsonthis is the perfect TypeScript library to convert your models to JSON objects.
15-
It supports custom property serializers, conditionally-visible properties, and much more.
14+
Jsonthis is a versatile TypeScript library designed to effortlessly convert your models into JSON objects.
15+
It offers extensive support for custom property serializers, conditional property visibility, and more.
1616

17-
Jsonthis is also the perfect companion to the [Sequelize](https://sequelize.org/) ORM library!
18-
To learn more, check out the [Sequelize support](#sequelize-support) section.
17+
Jsonthis seamlessly integrates with the [Sequelize](https://sequelize.org/) ORM library, making it an ideal companion
18+
for your data management needs. Explore the [Sequelize support](#sequelize-support) section for detailed instructions.
1919

2020
## Getting Started
2121

22-
This is the simplest way to use Jsonthis:
22+
Getting started with Jsonthis is quick and straightforward. Here's a simple example to get you going:
2323

2424
```typescript
2525
import {Json, JsonField, Jsonthis} from "jsonthis";
@@ -28,7 +28,7 @@ import {Json, JsonField, Jsonthis} from "jsonthis";
2828
class User {
2929
id: number;
3030
email: string;
31-
@JsonField(false)
31+
@JsonField(false) // visible=false - the "password" property will not be included in the JSON output
3232
password: string;
3333
registeredAt: Date = new Date();
3434

@@ -46,14 +46,14 @@ console.log(jsonthis.toJson(user));
4646
// { id: 1, email: '[email protected]', registeredAt: 2024-04-13T15:29:35.583Z }
4747
```
4848

49-
You can also use the `@JsonField` decorator to customize how `Jsonthis` serializes your properties.
50-
In the example above, the `password` property is hidden from the JSON output.
49+
Additionally, the `@JsonField` decorator empowers you to fine-tune the serialization process of your properties
50+
with Jsonthis. You can define custom serializers, change property visibility, and more.
5151

52-
Jsonthis also supports custom serializers and serialization options.
52+
## Customizing Serialization
5353

54-
## Change property name casing
54+
### Change Property Name Casing
5555

56-
You can enforce a specific casing for your properties in the JSON output.
56+
Jsonthis allows you to enforce specific casing for property names in the JSON output.
5757
By default, Jsonthis uses whatever casing you use in your TypeScript code,
5858
but you can change it to `camelCase`, `snake_case`, or `PascalCase`:
5959

@@ -76,13 +76,11 @@ console.log(new Jsonthis({case: "pascal"}).toJson(user));
7676
// { Id: 123, UserName: 'john-doe', RegisteredAt: 2024-04-13T20:42:22.121Z }
7777
```
7878

79-
## Change property visibility
80-
81-
The simplest customization you can do is to hide a property from the JSON output.
82-
As shown in the "Getting Started" example, you can use the `@JsonField` decorator to hide a property.
79+
### Change Property Visibility
8380

84-
You can pass the visible option directly to the `@JsonField` decorator,
85-
or you can use the `JsonFieldOptions` options object to specify more complex options:
81+
You can hide a property from the JSON output by setting the `visible` option to `false`.
82+
You can achieve this by passing `false` to the `@JsonField` decorator directly
83+
or by using the `JsonFieldOptions` object:
8684

8785
```typescript
8886
@Json
@@ -94,10 +92,10 @@ class User {
9492
}
9593
```
9694

97-
### Conditional visibility
95+
#### Conditional Visibility
9896

99-
Jsonthis serialization supports a user-defined context object that can be used to influence the serialization process.
100-
You can use this feature to conditionally hide or show properties based on the context.
97+
Jsonthis supports conditional property visibility based on a user-defined context.
98+
This allows you to dynamically show or hide properties as needed.
10199

102100
In the following example, the `email` property is only visible if the email owner is requesting it:
103101

@@ -133,7 +131,7 @@ console.log(jsonthis.toJson(user, {callerId: 2}));
133131
// { id: 1 }
134132
```
135133

136-
Note that this also works with nested objects:
134+
This also works with nested objects:
137135

138136
```typescript
139137
const user = new User(1, "[email protected]");
@@ -147,14 +145,14 @@ console.log(jsonthis.toJson(user, {callerId: 2}));
147145
// { id: 1, friend: { id: 2, email: '[email protected]' } }
148146
```
149147

150-
## Custom serializers
148+
### Custom serializers
151149

152-
You can use custom serializers to transform your properties in the final JSON output.
153-
Custom serializers can be **Global** or **Field-specific**.
150+
Jsonthis allows you to define custom serializers to transform property values during serialization.
151+
These can be either **global** or **field-specific**.
154152

155-
### Global serializer
153+
#### Global Serializer
156154

157-
You can register a global serializer for a specific type using the `Jsonthis.registerGlobalSerializer()` method:
155+
Register a global serializer for a specific type using `Jsonthis.registerGlobalSerializer()`:
158156

159157
```typescript
160158
function dateSerializer(value: Date): string {
@@ -175,9 +173,9 @@ console.log(jsonthis.toJson(user));
175173
// { id: 1, registeredAt: 'Sat, 13 Apr 2024 15:50:35 GMT' }
176174
```
177175

178-
### Field-specific serializer
176+
#### Field-Specific Serializer
179177

180-
You can use the `@JsonField` decorator to specify a custom serializer for a specific property:
178+
Utilize the `@JsonField` decorator to specify a custom serializer for a specific property:
181179

182180
```typescript
183181
function maskEmail(value: string): string {
@@ -197,7 +195,7 @@ console.log(jsonthis.toJson(user));
197195
// { id: 1, email: 'j******[email protected]' }
198196
```
199197

200-
### Contextual field-specific serializer
198+
#### Contextual Field-Specific Serializer
201199

202200
Jsonthis serialization supports a user-defined context object that can be used to further influence the serialization
203201
process:
@@ -225,9 +223,8 @@ console.log(jsonthis.toJson(user, {maskChar: "-"}));
225223
```
226224

227225
## Sequelize support
228-
229-
Jsonthis can work seamlessly with the [Sequelize](https://sequelize.org/) ORM library. In order to use Jsonthis with
230-
Sequelize, you need to specify it in library constructor:
226+
Jsonthis seamlessly integrates with the [Sequelize](https://sequelize.org/) ORM library.
227+
To utilize Jsonthis with Sequelize, simply specify it in the library constructor:
231228

232229
```typescript
233230
const sequelize = new Sequelize({ ... });
@@ -237,7 +234,8 @@ const jsonthis = new Jsonthis({
237234
});
238235
```
239236

240-
Now you can use the `toJSON()` method with Sequelize models and Jsonthis will intercept the serialization process:
237+
Now, Jsonthis will seamlessly intercept the serialization process when using the `toJSON()` method
238+
with Sequelize models:
241239

242240
```typescript
243241
function maskEmail(value: string): string {

0 commit comments

Comments
 (0)