MCPcopy Index your code
hub / github.com/fa0311/TwitterInternalAPIDocument / json_parser

Function json_parser

lib/js_parser/js_parser.py:120–169  ·  view source on GitHub ↗
(text: js_data)

Source from the content-addressed store, hash-verified

118
119
120def json_parser(text: js_data):
121 output = ""
122 reg_other = "[0-9a-zA-Z\s" + re.escape("!?$_.{}&=") + "]"
123 for data in text.children:
124 if type(data) is js_data:
125 json = json_parser(data)
126 else:
127 data = (
128 data.replace("null==t?void 0:", "{optional}")
129 .replace("?void 0:", "{void}")
130 .replace('"private"', "{private}")
131 .replace('"none"', "{none}")
132 )
133 placeholder = parentheses_placeholder(data)
134 json_child = ""
135 json = re.sub(
136 f"(,|^)(\.\.\.{reg_other}+)(,|$)",
137 r'\1"\2":"_"\3',
138 placeholder.text,
139 )
140 while json_child != json:
141 json_child = json
142 json = re.sub(
143 f"(,|^)(\.\.\.{reg_other}+)(,|$)",
144 r'\1"\2":"_"\3',
145 json_child,
146 )
147 json = re.sub(
148 f"(,|^)({reg_other}+)(:|$)",
149 r'\1"\2"\3',
150 json,
151 )
152 json = re.sub(
153 f"(:|^)({reg_other}+)(,|$)",
154 r'\1"\2"\3',
155 json,
156 )
157 args = [
158 "(" + parsed.replace('"', '\\"') + ")" for parsed in placeholder.list
159 ]
160 json = json.format(
161 *args,
162 optional="(optional) ",
163 void="?void 0:",
164 private="private",
165 none="none",
166 )
167 output += json
168 output = output.replace(':"_"{', ":{")
169 return "{" + output + "}"
170
171
172def parentheses_placeholder(text: str):

Callers 4

generator.pyFile · 0.85
get_graphqlFunction · 0.85
marge_exportsFunction · 0.85
get_freeze_objectFunction · 0.85

Calls 1

parentheses_placeholderFunction · 0.85

Tested by

no test coverage detected