# data-to-JSON conversion in JavaScript

Using the `JSON.stringify` method, you can convert JavaScript arrays and objects to JSON format. Let's look at an example.

Let's say we have a string containing an array in JSON format:

`let arr = [1, 2, 3, 4, 5, 'a', 'b'];`

Let's convert our array to a string:

`let json = JSON.stringify(arr);`

Given the following array:

`let json = ['user1', 'user2', 'user3', 'user4', 'user5'];`

Convert this array to JSON.

Given the following HTML:

`<ul> <li>city1</li> <li>city2</li> <li>city3</li> <li>city4</li> </ul>`

Get a list of cities in JSON.

Given the following HTML:

`<table> <tr> <th>Surname</th> <th>Name</th> </tr> <tr> <td>Daniels</td> <td>Jack</td> </tr> <tr> <td>Doe</td> <td>John</td> </tr> <tr> <td>Green</td> <td>Jimmy</td> </tr> </table>`

Get the represented JSON data as an object with the keys `surname` and `name`.

←→
↑
en ru