jsmn.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * MIT License
  3. *
  4. * Copyright (c) 2010 Serge Zaitsev
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * [License text continues...]
  14. */
  15. #ifndef JSMN_H
  16. #define JSMN_H
  17. #include <stddef.h>
  18. #include <jsmn/jsmn_h.h>
  19. #ifdef __cplusplus
  20. extern "C"
  21. {
  22. #endif
  23. #ifdef JSMN_STATIC
  24. #define JSMN_API static
  25. #else
  26. #define JSMN_API extern
  27. #endif
  28. /**
  29. * Create JSON parser over an array of tokens
  30. */
  31. JSMN_API void jsmn_init(jsmn_parser *parser);
  32. /**
  33. * Run JSON parser. It parses a JSON data string into and array of tokens, each
  34. * describing a single JSON object.
  35. */
  36. JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
  37. jsmntok_t *tokens, const unsigned int num_tokens);
  38. #ifndef JSMN_HEADER
  39. /* Implementation has been moved to jsmn.c */
  40. #endif /* JSMN_HEADER */
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. #endif /* JSMN_H */
  45. /* Custom Helper Functions */
  46. #ifndef JB_JSMN_EDIT
  47. #define JB_JSMN_EDIT
  48. /* Added in by JBlanked on 2024-10-16 for use in Flipper Zero SDK*/
  49. // Helper function to create a JSON object
  50. char *get_json(const char *key, const char *value);
  51. // Helper function to compare JSON keys
  52. int jsoneq(const char *json, jsmntok_t *tok, const char *s);
  53. // Return the value of the key in the JSON data
  54. char *get_json_value(char *key, const char *json_data);
  55. // Revised get_json_array_value function
  56. char *get_json_array_value(char *key, uint32_t index, const char *json_data);
  57. // Revised get_json_array_values function with correct token skipping
  58. char **get_json_array_values(char *key, char *json_data, int *num_values);
  59. int json_token_count(const char *json);
  60. #endif /* JB_JSMN_EDIT */