Skip to content

Commit aa8fa98

Browse files
committed
docs: add json example
1 parent 1e19189 commit aa8fa98

File tree

2 files changed

+103
-8
lines changed

2 files changed

+103
-8
lines changed

README.md

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ Store encrypted data alongside your existing data.
3232
- [Equality search (`cs_unique_v1`)](#equality-search-cs_unique_v1)
3333
- [Full-text search (`cs_match_v1`)](#full-text-search-cs_match_v1)
3434
- [Range queries (`cs_ore_64_8_v1`)](#range-queries-cs_ore_64_8_v1)
35-
- [JSONB support](#jsonb-support)
36-
- [Data format](#data-format)
35+
- [JSON and JSONB support](#json-and-jsonb-support)
36+
- [Configuring the index](#configuring-the-index)
37+
- [Inserting JSON data](#inserting-json-data)
38+
- [Reading JSON data](#reading-json-data)
39+
- [Advanced JSON queries](#advanced-json-queries)
40+
- [EQL payload data format](#eql-payload-data-format)
3741
- [Frequently Asked Questions](#frequently-asked-questions)
3842
- [How do I integrate CipherStash EQL with my application?](#how-do-i-integrate-cipherstash-eql-with-my-application)
3943
- [Can I use EQL without the CipherStash Proxy?](#can-i-use-eql-without-the-cipherstash-proxy)
@@ -333,13 +337,101 @@ Equivalent plaintext query:
333337
SELECT field, COUNT(*) FROM users GROUP BY field;
334338
```
335339

336-
## JSONB support
340+
## JSON and JSONB support
337341

338-
EQL supports encrypting and decrypting JSONB objects.
339-
We also support a wide range of JSONB functions and operators.
340-
You can read more about the JSONB support in the [JSONB reference guide][#jsonb-reference].
342+
EQL supports encrypting, decrypting, and searching JSON and JSONB objects.
341343

342-
## Data format
344+
### Configuring the index
345+
346+
Similar to how you configure indexes for text data, you can configure indexes for JSON and JSONB data.
347+
The only difference is that you need to specify the `cast_as` parameter as `json` or `jsonb`.
348+
349+
```sql
350+
SELECT cs_add_index_v1(
351+
'users',
352+
'encrypted_json',
353+
'ste_vec',
354+
'jsonb',
355+
'{"prefix": "users/encrypted_json"}' -- The prefix is in the form of "table/column"
356+
);
357+
```
358+
359+
You can read more about the index configuration options [here](https://github.com/cipherstash/encrypt-query-language/blob/main/docs/reference/INDEX.md).
360+
361+
### Inserting JSON data
362+
363+
When inserting JSON data, this works the same as inserting text data.
364+
You need to wrap the JSON data in the appropriate EQL payload.
365+
CipherStash Proxy will **encrypt** the data automatically.
366+
367+
**Example:**
368+
369+
Assuming you want to store the following JSON data:
370+
371+
```json
372+
{
373+
"name": "John Doe",
374+
"metadata": {
375+
"age": 42,
376+
}
377+
}
378+
```
379+
380+
The EQL payload would be:
381+
382+
```sql
383+
INSERT INTO users (encrypted_json) VALUES (
384+
'{"v":1,"k":"pt","p":"{\"name\":\"John Doe\",\"metadata\":{\"age\":42}}","i":{"t":"users","c":"encrypted_json"}}'
385+
);
386+
```
387+
388+
Data is stored in the database as:
389+
390+
```json
391+
{
392+
"i": {
393+
"c": "encrypted_json",
394+
"t": "users"
395+
},
396+
"k": "sv",
397+
"v": 1,
398+
"sv": [
399+
...ciphertext...
400+
]
401+
}
402+
```
403+
404+
### Reading JSON data
405+
406+
When querying data, select the encrypted column. CipherStash Proxy will **decrypt** the data automatically.
407+
408+
**Example:**
409+
410+
```sql
411+
SELECT encrypted_json FROM users;
412+
```
413+
414+
Data is returned as:
415+
416+
```json
417+
{
418+
"k": "pt",
419+
"p": "{\"metadata\":{\"age\":42},\"name\":\"John Doe\"}",
420+
"i": {
421+
"t": "users",
422+
"c": "encrypted_json"
423+
},
424+
"v": 1,
425+
"q": null
426+
}
427+
```
428+
429+
### Advanced JSON queries
430+
431+
We support a wide range of JSON/JSONB functions and operators.
432+
You can read more about the JSONB support in the [JSONB reference guide](https://github.com/cipherstash/encrypt-query-language/blob/main/docs/reference/JSON.md).
433+
434+
## EQL payload data format
343435

344436
Encrypted data is stored as `jsonb` with a specific schema:
345437

docs/reference/INDEX.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# Searchable index configuration
1+
# EQL index configuration
22

33
The following functions allow you to configure indexes for encrypted columns.
44
All these functions modify the `cs_configuration_v1` table in your database, and is added during the EQL installation.
55

6+
> **IMPORTANT:** When you modify or add an index, you must re-encrypt data that's already been stored in the database.
7+
The CipherStash encryption solution will encrypt the data based on the current state of the configuration.
8+
69
### Adding an index (`cs_add_index`)
710

811
Add an index to an encrypted column.

0 commit comments

Comments
 (0)