Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
33 lines (29 loc) · 978 Bytes

File metadata and controls

33 lines (29 loc) · 978 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from pprint import pprint
from jsonquerylang import parse, stringify
# parse the human friendly text format into the corresponding JSON format
text_query = '.friends | filter(.city == "new York") | sort(.age) | pick(.name, .age)'
json_query = parse(text_query)
pprint(json_query)
# ['pipe',
# ['get', 'friends'],
# ['filter', ['eq', ['get', 'city'], 'New York']],
# ['sort', ['get', 'age']],
# ['pick', ['get', 'name'], ['get', 'age']]]
# stringify the JSON format into the corresponding text format
print(stringify(json_query))
# """
# .friends
# | filter(.city == "new York")
# | sort(.age)
# | pick(.name, .age)
# """
# stringify with a custom indentation of 4 spaces
print(stringify(json_query, {"indentation": " "}))
# """
# .friends
# | filter(.city == "new York")
# | sort(.age)
# | pick(.name, .age)
# """
# now, both text_query and json_query can be used in the jsonquery() function,
# and json_query can be used in the compile() function.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.