json.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /**************************************************************************/
  2. /* json.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "json.h"
  31. #include "core/config/engine.h"
  32. #include "core/string/print_string.h"
  33. const char *JSON::tk_name[TK_MAX] = {
  34. "'{'",
  35. "'}'",
  36. "'['",
  37. "']'",
  38. "identifier",
  39. "string",
  40. "number",
  41. "':'",
  42. "','",
  43. "EOF",
  44. };
  45. String JSON::_make_indent(const String &p_indent, int p_size) {
  46. return p_indent.repeat(p_size);
  47. }
  48. String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_indent, bool p_sort_keys, HashSet<const void *> &p_markers, bool p_full_precision) {
  49. ERR_FAIL_COND_V_MSG(p_cur_indent > Variant::MAX_RECURSION_DEPTH, "...", "JSON structure is too deep. Bailing.");
  50. String colon = ":";
  51. String end_statement = "";
  52. if (!p_indent.is_empty()) {
  53. colon += " ";
  54. end_statement += "\n";
  55. }
  56. switch (p_var.get_type()) {
  57. case Variant::NIL:
  58. return "null";
  59. case Variant::BOOL:
  60. return p_var.operator bool() ? "true" : "false";
  61. case Variant::INT:
  62. return itos(p_var);
  63. case Variant::FLOAT: {
  64. double num = p_var;
  65. if (p_full_precision) {
  66. // Store unreliable digits (17) instead of just reliable
  67. // digits (14) so that the value can be decoded exactly.
  68. return String::num(num, 17 - (int)floor(log10(num)));
  69. } else {
  70. // Store only reliable digits (14) by default.
  71. return String::num(num, 14 - (int)floor(log10(num)));
  72. }
  73. }
  74. case Variant::PACKED_INT32_ARRAY:
  75. case Variant::PACKED_INT64_ARRAY:
  76. case Variant::PACKED_FLOAT32_ARRAY:
  77. case Variant::PACKED_FLOAT64_ARRAY:
  78. case Variant::PACKED_STRING_ARRAY:
  79. case Variant::ARRAY: {
  80. Array a = p_var;
  81. if (a.is_empty()) {
  82. return "[]";
  83. }
  84. String s = "[";
  85. s += end_statement;
  86. ERR_FAIL_COND_V_MSG(p_markers.has(a.id()), "\"[...]\"", "Converting circular structure to JSON.");
  87. p_markers.insert(a.id());
  88. bool first = true;
  89. for (const Variant &var : a) {
  90. if (first) {
  91. first = false;
  92. } else {
  93. s += ",";
  94. s += end_statement;
  95. }
  96. s += _make_indent(p_indent, p_cur_indent + 1) + _stringify(var, p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
  97. }
  98. s += end_statement + _make_indent(p_indent, p_cur_indent) + "]";
  99. p_markers.erase(a.id());
  100. return s;
  101. }
  102. case Variant::DICTIONARY: {
  103. String s = "{";
  104. s += end_statement;
  105. Dictionary d = p_var;
  106. ERR_FAIL_COND_V_MSG(p_markers.has(d.id()), "\"{...}\"", "Converting circular structure to JSON.");
  107. p_markers.insert(d.id());
  108. List<Variant> keys;
  109. d.get_key_list(&keys);
  110. if (p_sort_keys) {
  111. keys.sort();
  112. }
  113. bool first_key = true;
  114. for (const Variant &E : keys) {
  115. if (first_key) {
  116. first_key = false;
  117. } else {
  118. s += ",";
  119. s += end_statement;
  120. }
  121. s += _make_indent(p_indent, p_cur_indent + 1) + _stringify(String(E), p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
  122. s += colon;
  123. s += _stringify(d[E], p_indent, p_cur_indent + 1, p_sort_keys, p_markers);
  124. }
  125. s += end_statement + _make_indent(p_indent, p_cur_indent) + "}";
  126. p_markers.erase(d.id());
  127. return s;
  128. }
  129. default:
  130. return "\"" + String(p_var).json_escape() + "\"";
  131. }
  132. }
  133. Error JSON::_get_token(const char32_t *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str) {
  134. while (p_len > 0) {
  135. switch (p_str[index]) {
  136. case '\n': {
  137. line++;
  138. index++;
  139. break;
  140. }
  141. case 0: {
  142. r_token.type = TK_EOF;
  143. return OK;
  144. } break;
  145. case '{': {
  146. r_token.type = TK_CURLY_BRACKET_OPEN;
  147. index++;
  148. return OK;
  149. }
  150. case '}': {
  151. r_token.type = TK_CURLY_BRACKET_CLOSE;
  152. index++;
  153. return OK;
  154. }
  155. case '[': {
  156. r_token.type = TK_BRACKET_OPEN;
  157. index++;
  158. return OK;
  159. }
  160. case ']': {
  161. r_token.type = TK_BRACKET_CLOSE;
  162. index++;
  163. return OK;
  164. }
  165. case ':': {
  166. r_token.type = TK_COLON;
  167. index++;
  168. return OK;
  169. }
  170. case ',': {
  171. r_token.type = TK_COMMA;
  172. index++;
  173. return OK;
  174. }
  175. case '"': {
  176. index++;
  177. String str;
  178. while (true) {
  179. if (p_str[index] == 0) {
  180. r_err_str = "Unterminated String";
  181. return ERR_PARSE_ERROR;
  182. } else if (p_str[index] == '"') {
  183. index++;
  184. break;
  185. } else if (p_str[index] == '\\') {
  186. //escaped characters...
  187. index++;
  188. char32_t next = p_str[index];
  189. if (next == 0) {
  190. r_err_str = "Unterminated String";
  191. return ERR_PARSE_ERROR;
  192. }
  193. char32_t res = 0;
  194. switch (next) {
  195. case 'b':
  196. res = 8;
  197. break;
  198. case 't':
  199. res = 9;
  200. break;
  201. case 'n':
  202. res = 10;
  203. break;
  204. case 'f':
  205. res = 12;
  206. break;
  207. case 'r':
  208. res = 13;
  209. break;
  210. case 'u': {
  211. // hex number
  212. for (int j = 0; j < 4; j++) {
  213. char32_t c = p_str[index + j + 1];
  214. if (c == 0) {
  215. r_err_str = "Unterminated String";
  216. return ERR_PARSE_ERROR;
  217. }
  218. if (!is_hex_digit(c)) {
  219. r_err_str = "Malformed hex constant in string";
  220. return ERR_PARSE_ERROR;
  221. }
  222. char32_t v;
  223. if (is_digit(c)) {
  224. v = c - '0';
  225. } else if (c >= 'a' && c <= 'f') {
  226. v = c - 'a';
  227. v += 10;
  228. } else if (c >= 'A' && c <= 'F') {
  229. v = c - 'A';
  230. v += 10;
  231. } else {
  232. ERR_PRINT("Bug parsing hex constant.");
  233. v = 0;
  234. }
  235. res <<= 4;
  236. res |= v;
  237. }
  238. index += 4; //will add at the end anyway
  239. if ((res & 0xfffffc00) == 0xd800) {
  240. if (p_str[index + 1] != '\\' || p_str[index + 2] != 'u') {
  241. r_err_str = "Invalid UTF-16 sequence in string, unpaired lead surrogate";
  242. return ERR_PARSE_ERROR;
  243. }
  244. index += 2;
  245. char32_t trail = 0;
  246. for (int j = 0; j < 4; j++) {
  247. char32_t c = p_str[index + j + 1];
  248. if (c == 0) {
  249. r_err_str = "Unterminated String";
  250. return ERR_PARSE_ERROR;
  251. }
  252. if (!is_hex_digit(c)) {
  253. r_err_str = "Malformed hex constant in string";
  254. return ERR_PARSE_ERROR;
  255. }
  256. char32_t v;
  257. if (is_digit(c)) {
  258. v = c - '0';
  259. } else if (c >= 'a' && c <= 'f') {
  260. v = c - 'a';
  261. v += 10;
  262. } else if (c >= 'A' && c <= 'F') {
  263. v = c - 'A';
  264. v += 10;
  265. } else {
  266. ERR_PRINT("Bug parsing hex constant.");
  267. v = 0;
  268. }
  269. trail <<= 4;
  270. trail |= v;
  271. }
  272. if ((trail & 0xfffffc00) == 0xdc00) {
  273. res = (res << 10UL) + trail - ((0xd800 << 10UL) + 0xdc00 - 0x10000);
  274. index += 4; //will add at the end anyway
  275. } else {
  276. r_err_str = "Invalid UTF-16 sequence in string, unpaired lead surrogate";
  277. return ERR_PARSE_ERROR;
  278. }
  279. } else if ((res & 0xfffffc00) == 0xdc00) {
  280. r_err_str = "Invalid UTF-16 sequence in string, unpaired trail surrogate";
  281. return ERR_PARSE_ERROR;
  282. }
  283. } break;
  284. case '"':
  285. case '\\':
  286. case '/': {
  287. res = next;
  288. } break;
  289. default: {
  290. r_err_str = "Invalid escape sequence.";
  291. return ERR_PARSE_ERROR;
  292. }
  293. }
  294. str += res;
  295. } else {
  296. if (p_str[index] == '\n') {
  297. line++;
  298. }
  299. str += p_str[index];
  300. }
  301. index++;
  302. }
  303. r_token.type = TK_STRING;
  304. r_token.value = str;
  305. return OK;
  306. } break;
  307. default: {
  308. if (p_str[index] <= 32) {
  309. index++;
  310. break;
  311. }
  312. if (p_str[index] == '-' || is_digit(p_str[index])) {
  313. //a number
  314. const char32_t *rptr;
  315. double number = String::to_float(&p_str[index], &rptr);
  316. index += (rptr - &p_str[index]);
  317. r_token.type = TK_NUMBER;
  318. r_token.value = number;
  319. return OK;
  320. } else if (is_ascii_alphabet_char(p_str[index])) {
  321. String id;
  322. while (is_ascii_alphabet_char(p_str[index])) {
  323. id += p_str[index];
  324. index++;
  325. }
  326. r_token.type = TK_IDENTIFIER;
  327. r_token.value = id;
  328. return OK;
  329. } else {
  330. r_err_str = "Unexpected character.";
  331. return ERR_PARSE_ERROR;
  332. }
  333. }
  334. }
  335. }
  336. return ERR_PARSE_ERROR;
  337. }
  338. Error JSON::_parse_value(Variant &value, Token &token, const char32_t *p_str, int &index, int p_len, int &line, int p_depth, String &r_err_str) {
  339. if (p_depth > Variant::MAX_RECURSION_DEPTH) {
  340. r_err_str = "JSON structure is too deep. Bailing.";
  341. return ERR_OUT_OF_MEMORY;
  342. }
  343. if (token.type == TK_CURLY_BRACKET_OPEN) {
  344. Dictionary d;
  345. Error err = _parse_object(d, p_str, index, p_len, line, p_depth + 1, r_err_str);
  346. if (err) {
  347. return err;
  348. }
  349. value = d;
  350. } else if (token.type == TK_BRACKET_OPEN) {
  351. Array a;
  352. Error err = _parse_array(a, p_str, index, p_len, line, p_depth + 1, r_err_str);
  353. if (err) {
  354. return err;
  355. }
  356. value = a;
  357. } else if (token.type == TK_IDENTIFIER) {
  358. String id = token.value;
  359. if (id == "true") {
  360. value = true;
  361. } else if (id == "false") {
  362. value = false;
  363. } else if (id == "null") {
  364. value = Variant();
  365. } else {
  366. r_err_str = "Expected 'true','false' or 'null', got '" + id + "'.";
  367. return ERR_PARSE_ERROR;
  368. }
  369. } else if (token.type == TK_NUMBER) {
  370. value = token.value;
  371. } else if (token.type == TK_STRING) {
  372. value = token.value;
  373. } else {
  374. r_err_str = "Expected value, got " + String(tk_name[token.type]) + ".";
  375. return ERR_PARSE_ERROR;
  376. }
  377. return OK;
  378. }
  379. Error JSON::_parse_array(Array &array, const char32_t *p_str, int &index, int p_len, int &line, int p_depth, String &r_err_str) {
  380. Token token;
  381. bool need_comma = false;
  382. while (index < p_len) {
  383. Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
  384. if (err != OK) {
  385. return err;
  386. }
  387. if (token.type == TK_BRACKET_CLOSE) {
  388. return OK;
  389. }
  390. if (need_comma) {
  391. if (token.type != TK_COMMA) {
  392. r_err_str = "Expected ','";
  393. return ERR_PARSE_ERROR;
  394. } else {
  395. need_comma = false;
  396. continue;
  397. }
  398. }
  399. Variant v;
  400. err = _parse_value(v, token, p_str, index, p_len, line, p_depth, r_err_str);
  401. if (err) {
  402. return err;
  403. }
  404. array.push_back(v);
  405. need_comma = true;
  406. }
  407. r_err_str = "Expected ']'";
  408. return ERR_PARSE_ERROR;
  409. }
  410. Error JSON::_parse_object(Dictionary &object, const char32_t *p_str, int &index, int p_len, int &line, int p_depth, String &r_err_str) {
  411. bool at_key = true;
  412. String key;
  413. Token token;
  414. bool need_comma = false;
  415. while (index < p_len) {
  416. if (at_key) {
  417. Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
  418. if (err != OK) {
  419. return err;
  420. }
  421. if (token.type == TK_CURLY_BRACKET_CLOSE) {
  422. return OK;
  423. }
  424. if (need_comma) {
  425. if (token.type != TK_COMMA) {
  426. r_err_str = "Expected '}' or ','";
  427. return ERR_PARSE_ERROR;
  428. } else {
  429. need_comma = false;
  430. continue;
  431. }
  432. }
  433. if (token.type != TK_STRING) {
  434. r_err_str = "Expected key";
  435. return ERR_PARSE_ERROR;
  436. }
  437. key = token.value;
  438. err = _get_token(p_str, index, p_len, token, line, r_err_str);
  439. if (err != OK) {
  440. return err;
  441. }
  442. if (token.type != TK_COLON) {
  443. r_err_str = "Expected ':'";
  444. return ERR_PARSE_ERROR;
  445. }
  446. at_key = false;
  447. } else {
  448. Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
  449. if (err != OK) {
  450. return err;
  451. }
  452. Variant v;
  453. err = _parse_value(v, token, p_str, index, p_len, line, p_depth, r_err_str);
  454. if (err) {
  455. return err;
  456. }
  457. object[key] = v;
  458. need_comma = true;
  459. at_key = true;
  460. }
  461. }
  462. r_err_str = "Expected '}'";
  463. return ERR_PARSE_ERROR;
  464. }
  465. void JSON::set_data(const Variant &p_data) {
  466. data = p_data;
  467. text.clear();
  468. }
  469. Error JSON::_parse_string(const String &p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
  470. const char32_t *str = p_json.ptr();
  471. int idx = 0;
  472. int len = p_json.length();
  473. Token token;
  474. r_err_line = 0;
  475. String aux_key;
  476. Error err = _get_token(str, idx, len, token, r_err_line, r_err_str);
  477. if (err) {
  478. return err;
  479. }
  480. err = _parse_value(r_ret, token, str, idx, len, r_err_line, 0, r_err_str);
  481. // Check if EOF is reached
  482. // or it's a type of the next token.
  483. if (err == OK && idx < len) {
  484. err = _get_token(str, idx, len, token, r_err_line, r_err_str);
  485. if (err || token.type != TK_EOF) {
  486. r_err_str = "Expected 'EOF'";
  487. // Reset return value to empty `Variant`
  488. r_ret = Variant();
  489. return ERR_PARSE_ERROR;
  490. }
  491. }
  492. return err;
  493. }
  494. Error JSON::parse(const String &p_json_string, bool p_keep_text) {
  495. Error err = _parse_string(p_json_string, data, err_str, err_line);
  496. if (err == Error::OK) {
  497. err_line = 0;
  498. }
  499. if (p_keep_text) {
  500. text = p_json_string;
  501. }
  502. return err;
  503. }
  504. String JSON::get_parsed_text() const {
  505. return text;
  506. }
  507. String JSON::stringify(const Variant &p_var, const String &p_indent, bool p_sort_keys, bool p_full_precision) {
  508. Ref<JSON> jason;
  509. jason.instantiate();
  510. HashSet<const void *> markers;
  511. return jason->_stringify(p_var, p_indent, 0, p_sort_keys, markers, p_full_precision);
  512. }
  513. Variant JSON::parse_string(const String &p_json_string) {
  514. Ref<JSON> jason;
  515. jason.instantiate();
  516. Error error = jason->parse(p_json_string);
  517. ERR_FAIL_COND_V_MSG(error != Error::OK, Variant(), vformat("Parse JSON failed. Error at line %d: %s", jason->get_error_line(), jason->get_error_message()));
  518. return jason->get_data();
  519. }
  520. void JSON::_bind_methods() {
  521. ClassDB::bind_static_method("JSON", D_METHOD("stringify", "data", "indent", "sort_keys", "full_precision"), &JSON::stringify, DEFVAL(""), DEFVAL(true), DEFVAL(false));
  522. ClassDB::bind_static_method("JSON", D_METHOD("parse_string", "json_string"), &JSON::parse_string);
  523. ClassDB::bind_method(D_METHOD("parse", "json_text", "keep_text"), &JSON::parse, DEFVAL(false));
  524. ClassDB::bind_method(D_METHOD("get_data"), &JSON::get_data);
  525. ClassDB::bind_method(D_METHOD("set_data", "data"), &JSON::set_data);
  526. ClassDB::bind_method(D_METHOD("get_parsed_text"), &JSON::get_parsed_text);
  527. ClassDB::bind_method(D_METHOD("get_error_line"), &JSON::get_error_line);
  528. ClassDB::bind_method(D_METHOD("get_error_message"), &JSON::get_error_message);
  529. ADD_PROPERTY(PropertyInfo(Variant::NIL, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT), "set_data", "get_data"); // Ensures that it can be serialized as binary.
  530. }
  531. ////
  532. ////////////
  533. Ref<Resource> ResourceFormatLoaderJSON::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
  534. if (r_error) {
  535. *r_error = ERR_FILE_CANT_OPEN;
  536. }
  537. if (!FileAccess::exists(p_path)) {
  538. *r_error = ERR_FILE_NOT_FOUND;
  539. return Ref<Resource>();
  540. }
  541. Ref<JSON> json;
  542. json.instantiate();
  543. Error err = json->parse(FileAccess::get_file_as_string(p_path), Engine::get_singleton()->is_editor_hint());
  544. if (err != OK) {
  545. String err_text = "Error parsing JSON file at '" + p_path + "', on line " + itos(json->get_error_line()) + ": " + json->get_error_message();
  546. if (Engine::get_singleton()->is_editor_hint()) {
  547. // If running on editor, still allow opening the JSON so the code editor can edit it.
  548. WARN_PRINT(err_text);
  549. } else {
  550. if (r_error) {
  551. *r_error = err;
  552. }
  553. ERR_PRINT(err_text);
  554. return Ref<Resource>();
  555. }
  556. }
  557. if (r_error) {
  558. *r_error = OK;
  559. }
  560. return json;
  561. }
  562. void ResourceFormatLoaderJSON::get_recognized_extensions(List<String> *p_extensions) const {
  563. p_extensions->push_back("json");
  564. }
  565. bool ResourceFormatLoaderJSON::handles_type(const String &p_type) const {
  566. return (p_type == "JSON");
  567. }
  568. String ResourceFormatLoaderJSON::get_resource_type(const String &p_path) const {
  569. String el = p_path.get_extension().to_lower();
  570. if (el == "json") {
  571. return "JSON";
  572. }
  573. return "";
  574. }
  575. Error ResourceFormatSaverJSON::save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags) {
  576. Ref<JSON> json = p_resource;
  577. ERR_FAIL_COND_V(json.is_null(), ERR_INVALID_PARAMETER);
  578. String source = json->get_parsed_text().is_empty() ? JSON::stringify(json->get_data(), "\t", false, true) : json->get_parsed_text();
  579. Error err;
  580. Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err);
  581. ERR_FAIL_COND_V_MSG(err, err, "Cannot save json '" + p_path + "'.");
  582. file->store_string(source);
  583. if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
  584. return ERR_CANT_CREATE;
  585. }
  586. return OK;
  587. }
  588. void ResourceFormatSaverJSON::get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const {
  589. Ref<JSON> json = p_resource;
  590. if (json.is_valid()) {
  591. p_extensions->push_back("json");
  592. }
  593. }
  594. bool ResourceFormatSaverJSON::recognize(const Ref<Resource> &p_resource) const {
  595. return p_resource->get_class_name() == "JSON"; //only json, not inherited
  596. }