You must be logged in to edit this page
Kanso includes some tools for manipulating and uploading JSON data. This is a good way to get some test data into your app's database and start experimenting with views.
### Data formats
The documents are stored as JSON and each file can contain either a single document or an array of documents.
Example .json file with a single document:
```javascript
{
"year": 1997,
"make": "Ford",
"model": "E350",
"description": "ac, abs, moon",
"price": 3000.00
}
```
Example .json file with multiple documents:
```javascript
[
{
"year": 1997,
"make": "Ford",
"model": "E350",
"description": "ac, abs, moon",
"price": 3000
},
{
"year": 1999,
"make": "Chevy",
"model": "Venture \"Extended Edition\"",
"description": "",
"price": 4900
}
]
```
### Uploading data
Create an example.json file containing some simple data structure (such as first example above). I would normally store this inside a 'data' directory.
You can then upload the documents to a CouchDB database using the following command:
```
kanso upload data/example.json http://localhost:5984/example
```
### Adding _id properties
If you attempted to upload the above example documents, you'll get an error reporting that the documents are missing _id attributes. The upload command requires _id attributes to avoid duplicating data in the database. Otherwise, multiple uploads would duplicate the data and it can be complicated to untangle. This can get even more confusing if the documents are uploaded to multiple dbs replicating with each other. By forcing all documents to have an _id before uploading, conflicts will be properly detected.
Adding _id properties to each document manually is arduous. Thankfully, Kanso provides some tools for adding/removing document _ids.
```
kanso transform add-ids <source> <output>
```
Note that this will fail if you specify the same file for source and output, since the output file is wiped before the input file is read. In this case you could use the following:
```
kanso transform add-ids data/example.json data/example-with-ids.json
```
Once the documents have an _id, the following upload command should succeed:
```
kanso upload data/example-with-ids.json http://localhost:5984/example
```
### Upload multiple files
You can also upload an entire directory of data files:
```
kanso upload data http://localhost:5984/example
```
### Next
Make use of this example data: [[Defining_queries]]