-
Notifications
You must be signed in to change notification settings - Fork 0
/
jgen.py
73 lines (60 loc) · 2.04 KB
/
jgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# import json
# data = {}
# data['q'] = 'value'
# # json_data = json.dumps(data)
# # data['people'].append({
# # 'name': 'Larry',
# # 'website': 'google.com',
# # 'from': 'Michigan'
# # })
# # data['people'].append({
# # 'name': 'Tim',
# # 'website': 'apple.com',
# # 'from': 'Alabama'
# # })
# with open('data.json', 'w') as outfile:
# json.dump(data, outfile)
# import json
# from pprint import pprint
# json_input = '{"intent": {"name": "greet", "confidence": 0.7028232958181023}, "entities": [], "intent_ranking": [{"name": "greet", "confidence": 0.7028232958181023}, {"name": "goodbye", "confidence": 0.14298864950963153}, {"name": "quiz_search", "confidence": 0.08743951469218535}, {"name": "affirm", "confidence": 0.06674853998008078}], "text": "hello"}{"intent": {"name": "greet", "confidence": 0.7028232958181023}, "entities": [], "intent_ranking": [{"name": "greet", "confidence": 0.7028232958181023}, {"name": "goodbye", "confidence": 0.14298864950963153}, {"name": "quiz_search", "confidence": 0.08743951469218535}, {"name": "affirm", "confidence": 0.06674853998008078}], "text": "hello"}'
# json_data=open('data.json').read()
# data = json.loads(json_data)
# pprint(data)
# try:
# decoded = json.loads(json_input)
# # Access data
# for x in decoded['intent']:
# print(x['name'])
# except (ValueError, KeyError, TypeError):
# print("JSON format error")
# for element in data['drinks']:
# print(element)
import json
from pprint import pprint
st = """{
"intent": {
"name": "greet",
"confidence": 0.7028232958181023
},
"entities": [],
"intent_ranking":
[{
"name": "greet",
"confidence": 0.7028232958181023
},
{
"name": "goodbye",
"confidence": 0.14298864950963153
},
{
"name": "quiz_search",
"confidence": 0.08743951469218535
},
{
"name": "affirm",
"confidence": 0.06674853998008078
}],
"text": "hello"
}"""
data = json.load(st)
print(data['intent']['name'])