Giter VIP home page Giter VIP logo

9xn / json Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 16 KB

This is a simple JSON library implemented in C that allows you to create JSON objects and convert them to formatted strings. It provides basic functionality for adding key-value pairs to a JSON object and obtaining the JSON representation as a string.

License: GNU Affero General Public License v3.0

C 100.00%

json's Introduction

json

This is a simple JSON library implemented in C that allows you to create JSON objects and convert them to formatted strings. It provides basic functionality for adding key-value pairs to a JSON object and obtaining the JSON representation as a string.

Usage

  1. Clone the repository to your local machine:
git clone https://github.com/9xN/json.git
  1. Include the json.h header file in your C program:
#include "json.h"
  1. Create a jsonObject instance and initialize it:
jsonObject myJson;
myJson.count = 0;
  1. Add key-value pairs to the JSON object using the json_add_pair function:
json_add_pair(&myJson, "key1", "value1");
json_add_pair(&myJson, "key2", "value2");
// Add more key-value pairs as needed
  1. Convert the JSON object to a formatted string using the json_to_string function:
char *jsonString = json_to_string(&myJson);
  1. Use the resulting jsonString as needed, such as in web requests or other contexts.

  2. Don't forget to free the memory allocated for the JSON string when you're done using it:

free(jsonString);

Example

Here's an example program that demonstrates the usage of the JSON library:

#include <stdio.h>
#include <stdlib.h>
#include "json.h"

int main() {
    jsonObject myJson;
    myJson.count = 0;

    json_add_pair(&myJson, "name", "John");
    json_add_pair(&myJson, "age", "25");
    json_add_pair(&myJson, "city", "New York");

    char *jsonString = json_to_string(&myJson);
    if (jsonString != NULL) {
        printf("JSON string: %s\n", jsonString);
        free(jsonString);
    }

    return 0;
}

Limitations

  • This JSON library has a maximum JSON size limit of 4096 characters. If you need to handle larger JSON objects, you may need to modify the library accordingly.
  • This library provides basic functionality for creating JSON objects and converting them to strings. It does not include advanced features like parsing JSON strings or handling nested objects.

Contributions

Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

License

This JSON library is open source and distributed under the GNU Affero General Public License.

json's People

Contributors

9xn avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.