json.cpp 18 KB

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