├── library.properties ├── keywords.txt ├── jsonencoder.h ├── jsonencoder.cpp └── README.md /library.properties: -------------------------------------------------------------------------------- 1 | name=JSON Encoder 2 | version=1.0.0 3 | author=Saurav Sajeev 4 | maintainer=Saurav Sajeev 5 | sentence=Encode/Decode json/URL format strings for web transmission. 6 | paragraph=Arduino library to encode and decode json/URL format strings for web transmission. 7 | category=json/Web/Server 8 | url=https://github.com/styropyr0/JSON_Encoder 9 | architectures=esp8266, esp32 10 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ########################################## 2 | # Encode JSON to URL format and vice versa 3 | ########################################## 4 | 5 | ########################################## 6 | # Methods and functions (KEYWORD1) 7 | ########################################## 8 | encode KEYWORD1 9 | decode KEYWORD1 10 | 11 | ########################################## 12 | # Constants (LITERAL1) 13 | ########################################## 14 | 15 | -------------------------------------------------------------------------------- /jsonencoder.h: -------------------------------------------------------------------------------- 1 | #ifndef jsonencoder 2 | #define jsonencoder 3 | #include 4 | /** 5 | * @brief Converts a JSON string into URL encoded string. 6 | * 7 | * @param jsonString The JSON format string. 8 | * @return URL encoded string. 9 | */ 10 | String encode(String jsonString); 11 | 12 | /** 13 | * @brief Converts an URL encoded string into JSON string. 14 | * 15 | * @param jsonString The URL encoded string. 16 | * @return JSON format string. 17 | */ 18 | String decode(String codedString); 19 | 20 | #endif -------------------------------------------------------------------------------- /jsonencoder.cpp: -------------------------------------------------------------------------------- 1 | #include "jsonencoder.h" 2 | 3 | /** 4 | * @brief Converts a JSON string into URL encoded string. 5 | * 6 | * @param jsonString The JSON format string. 7 | * @return URL encoded string. 8 | */ 9 | String encode(String jsonString){ 10 | for(int i=0; i **Include Library** > **Manage Libraries...**. 18 | 3. Search for `JSON_Encoder` and click **Install**. 19 | 20 | ### Manual Installation 21 | 22 | 1. Download the library as a ZIP file from the [GitHub repository](https://github.com/styropyr0/JSON_Encoder). 23 | 2. Open the Arduino IDE. 24 | 3. Navigate to **Sketch** > **Include Library** > **Add .ZIP Library...**. 25 | 4. Select the downloaded ZIP file. 26 | 27 | ## API Reference 28 | 29 | ### `encode(String jsonString)` 30 | 31 | - **Description**: Converts a JSON string into a URL-encoded string. 32 | - **Parameters**: 33 | - `jsonString` (String): The input JSON string. 34 | - **Returns**: A URL-encoded string. 35 | 36 | ### `decode(String codedString)` 37 | 38 | - **Description**: Converts a URL-encoded string back into a JSON string. 39 | - **Parameters**: 40 | - `codedString` (String): The URL-encoded input string. 41 | - **Returns**: A JSON-formatted string. 42 | 43 | ## Example Usage 44 | 45 | ### Encoding a JSON String 46 | 47 | ```cpp 48 | #include 49 | 50 | void setup() { 51 | Serial.begin(9600); 52 | String json = "{\"temperature\":23.5,\"humidity\":45}"; 53 | String encoded = encode(json); 54 | Serial.println("Encoded: " + encoded); 55 | } 56 | 57 | void loop() { 58 | // No loop actions needed 59 | } 60 | ``` 61 | 62 | ### Decoding a URL-Encoded String 63 | 64 | ```cpp 65 | #include 66 | 67 | void setup() { 68 | Serial.begin(9600); 69 | String encoded = "%7B%22temperature%22%3A23.5%2C%22humidity%22%3A45%7D"; 70 | String json = decode(encoded); 71 | Serial.println("Decoded: " + json); 72 | } 73 | 74 | void loop() { 75 | // No loop actions needed 76 | } 77 | ``` 78 | 79 | ### Sample Output 80 | 81 | **Encoded**: `%7B%22temperature%22%3A23.5%2C%22humidity%22%3A45%7D` 82 | **Decoded**: `{"temperature":23.5,"humidity":45}` 83 | 84 | ## Contributing 85 | 86 | Contributions are welcome! Feel free to open issues or submit pull requests to improve the library. 87 | 88 | ## License 89 | 90 | This library is licensed under the [MIT License](LICENSE). 91 | 92 | ## Author 93 | 94 | Developed by **Saurav Sajeev**. 95 | --------------------------------------------------------------------------------