Code Monkey home page Code Monkey logo

json5's Introduction

  • ๐Ÿ‘‹ Hi, Iโ€™m @P-i-N
  • ๐Ÿ‘€ Iโ€™m interested in ...
  • ๐ŸŒฑ Iโ€™m currently learning ...

json5's People

Contributors

gbooker avatar p-i-n avatar

Stargazers

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

Watchers

 avatar  avatar

json5's Issues

Fix the README

In the Serialize custom type example, write and read function should be a template specialization.
So,

// Let's have a 3D vector struct:
struct vec3 { float x, y, z; };

// Let's have a triangle struct with 'vec3' members
struct Triangle
{
	vec3 a, b, c;
};

JSON5_CLASS(Triangle, a, b, c)

namespace json5::detail {

// Write vec3 as JSON array of 3 numbers
template<>
inline json5::value write( writer &w, const vec3 &in )
{
	w.push_array();
	w += write( w, in.x );
	w += write( w, in.y );
	w += write( w, in.z );
	return w.pop();
}

// Read vec3 from JSON array
template<>
inline error read( const json5::value &in, vec3 &out )
{
	return read( json5::array_view( in ), out.x, out.y, out.z );
}

} // namespace json5::detail

This is the right way to do this.

Also, please make a note about the #include order. It seems like json5_input.hpp should be included in prior to json5_reflect.hpp.

Q: how to render sub-level of json document to a string

Given a json document with multiple sub levels, for example:

{
    "foo": {
       "bar": {
           alpha: 1.0,
           beta: 2.1
       }
    }
}

If I navigate such that json5::value points to foo/bar, how can I see this portion of the document as a string:

{ "alpha": 1.0, "beta": 2.1 }

I took a look at the the to_string`` functionality in json5_reflect, but did not see a way to use this to convert the json5::value``` subtree to its associated json string. Does this functionality exist?

bug in parser::parse_identifier, a fix

In json, if an identifier is quoted, it may contain any non-string terminating character. This parser will not parse the following for example:

{ "this*test": 123 }

due to the "*" character not being in alpha-numeric set. However if quoted, the above is valid. The following code needs to be changed in json5_input.hpp::parse_identifier. Change:

while ( !eof() )
{
    string_buffer_add( next() );

    int ch = peek();
    if ( !isalpha( ch ) && !isdigit( ch ) && ch != '_' )
	break;
}

to this:

while ( !eof() )
{
    string_buffer_add( next() );

    int ch = peek();
    if ((!isString && !isalpha(ch) && !isdigit(ch) && ch != '_' ) || (isString && ch == firstCh))
	break;
}

A flag was set previously in this function isString which indicates whether the identifier is quoted or not.

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.