How to get and show specific values from JSON file with Flask

Solution
import json
from flask import (
    Flask,
    render_template,
    request
)

app = Flask(__name__)

@app.route('/')
def index():
    q = request.args.get('q')
    with open('intents.json') as f:
        data = json.load(f)
    data = data.get('intents', [])
    tags = [intent['tag'] for intent in data]
    if q:
        data = [intent for intent in data if q in intent['tag']]
    return render_template('index.html', **locals())


  
    
    Index
  
  

    
{% for tag in tags | sort -%}
{% for intent in data | sort(attribute='tag') -%}
{{ intent.tag }}
{{ intent.patterns | join(', ') }}
{{ intent.responses | join(', ') }}
{% endfor -%}