Skip to content

Commit 8ca1e7e

Browse files
committed
Add Google Colab demo notebook
1 parent 04c2e34 commit 8ca1e7e

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

demo.ipynb

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {"provenance": []},
6+
"kernelspec": {"name": "python3", "display_name": "Python 3"}
7+
},
8+
"cells": [
9+
{
10+
"cell_type": "markdown",
11+
"metadata": {},
12+
"source": [
13+
"# JQ-By-Example Demo\n",
14+
"\n",
15+
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nulone/jq-by-example/blob/main/demo.ipynb)\n",
16+
"\n",
17+
"**AI-powered jq filter synthesis from input/output JSON examples.**\n",
18+
"\n",
19+
"GitHub: [nulone/jq-by-example](https://github.com/nulone/jq-by-example)"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"metadata": {},
25+
"source": [
26+
"# Setup\n",
27+
"!pip install -q jq-by-example\n",
28+
"!apt-get install -y jq > /dev/null 2>&1\n",
29+
"!echo \"jq version: $(jq --version)\""
30+
],
31+
"execution_count": null,
32+
"outputs": []
33+
},
34+
{
35+
"cell_type": "code",
36+
"metadata": {},
37+
"source": [
38+
"# Set API Key\n",
39+
"from getpass import getpass\n",
40+
"import os\n",
41+
"\n",
42+
"api_key = getpass('Enter your OpenAI API key: ')\n",
43+
"os.environ['OPENAI_API_KEY'] = api_key\n",
44+
"print('✅ API key set')"
45+
],
46+
"execution_count": null,
47+
"outputs": []
48+
},
49+
{
50+
"cell_type": "markdown",
51+
"metadata": {},
52+
"source": ["## Example 1: Extract nested field"]
53+
},
54+
{
55+
"cell_type": "code",
56+
"metadata": {},
57+
"source": [
58+
"!jq-by-example \\\n",
59+
" --input '{\"user\": {\"name\": \"Alice\", \"age\": 30}}' \\\n",
60+
" --output '\"Alice\"' \\\n",
61+
" --desc 'Extract user name'"
62+
],
63+
"execution_count": null,
64+
"outputs": []
65+
},
66+
{
67+
"cell_type": "markdown",
68+
"metadata": {},
69+
"source": ["## Example 2: Filter array"]
70+
},
71+
{
72+
"cell_type": "code",
73+
"metadata": {},
74+
"source": [
75+
"!jq-by-example \\\n",
76+
" --input '[{\"name\": \"Alice\", \"active\": true}, {\"name\": \"Bob\", \"active\": false}]' \\\n",
77+
" --output '[{\"name\": \"Alice\", \"active\": true}]' \\\n",
78+
" --desc 'Keep only active users'"
79+
],
80+
"execution_count": null,
81+
"outputs": []
82+
},
83+
{
84+
"cell_type": "markdown",
85+
"metadata": {},
86+
"source": ["## Try your own!\n", "Modify the values below:"]
87+
},
88+
{
89+
"cell_type": "code",
90+
"metadata": {},
91+
"source": [
92+
"# Your custom example\n",
93+
"INPUT = '{\"data\": [1, 2, 3]}'\n",
94+
"OUTPUT = '[2, 4, 6]'\n",
95+
"DESC = 'Double each number'\n",
96+
"\n",
97+
"!jq-by-example --input '{INPUT}' --output '{OUTPUT}' --desc '{DESC}'"
98+
],
99+
"execution_count": null,
100+
"outputs": []
101+
}
102+
]
103+
}

0 commit comments

Comments
 (0)