Coder Social home page Coder Social logo

ghh_json's People

Contributors

garrisonhh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ghh_json's Issues

Error if empty array

Hi,

Thank you for your great and useful json parser! It's super easy to use.

I've got an error when trying to parse a json object with an empty array. Example:

    json_t json2;
    char *test = "{\"foo\":\"bar\",\"boo\":[]}";
    json_load(&json2, test);

Error:

JSON ERROR: unknown token, expected value.
     1 | {"foo":"bar","boo":[]}
       |     

Kind regards,

Merging two JSON objects

Is there an easy way to merge two JSON objects? E.g. if they have the same keys then overwrite, otherwise add new?

Thanks,
Bartek

Non-scientific floating point numbers not supported

Hi,

Thanks for this great library! I noticed that non-scientific floating point numbers are not supported, i.e. they are parsed into completely wrong numbers which was hard to debug :)

E.g. this works: 1e-3 but this doesn't: 0.001, it actually outputs 0.1.

I propose to simplify json_expect_number to this code:

#include <stdlib.h>. // for strtod
...
static double json_expect_number(json_ctx_t *ctx) {
    // Convert string to double
    double num = strtod(&ctx->text[ctx->index], NULL);

    // Move pointer until not a comma and not end of line
    while (ctx->text[ctx->index] != ',' && ctx->text[ctx->index] != '\n' && ctx->text[ctx->index] != ']') {
        ctx->index++;
    }

    return num;
}

Works well this way with both scientific and regular notation.

Cheers,
Bartek

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.