Coder Social home page Coder Social logo

hjson-php's Introduction

NPM Maven Central PyPI nuget Packagist crate crate Go Pkg LuaRocks

Hjson, a user interface for JSON

Hjson

Adds comments, makes it nicer to read and avoids comma mistakes.

For details see hjson.github.io.

hjson-php's People

Contributors

andvaranaut avatar chrisputnam9 avatar dqsully avatar iainhallam avatar jawb avatar laktak avatar nichtich avatar peter279k avatar s-patompong avatar sprak3000 avatar trobro 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  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  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  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hjson-php's Issues

Incorrect stringification of falsy strings

HJSONStringifier->quote has a check at the beginning which returns an empty quoted string if the string is falsy:

private function quote($string = null, $gap = null, $hasComment = null, $isRootObject = null)
    {
        if (!$string) {
            return '""';
        }
...}

This means that if the string is falsy, such as if it contains just "0", it won't be serialized correctly:

php > echo (new HJSON\HJSONStringifier)->stringify(["A", "0"]);
[
  A
  ""
]

The fix is simply changing the !$string test to $string === ''. As HJSONStringifier->quote is a private function and, as far as I can see, there is no way for it to be called with anything other than a string, this should not affect anything else.

Travis fails for PHP 5.5

@iainhallam @jawb I've added a Travis build but it fails for PHP 5.5.21 with

HJSONParserTest::testAll
mb_ereg_search_init(): mbregex compile err: invalid code point value

see here

Can this be fixed or should we remove builds for PHP <= 5.5?

Multiline strings where a line is just 0 gets truncated

Given the following JSON:

{
  "foo": "bar\n0"
}

Converting this to HJSON using HJSONStringifier results in:

{
  foo:
    '''
    bar

    '''
}

The line with 0 gets removed completely, including the indentation.

It looks like the culprit is this if statement whose purpose I assume is to not include indentation for empty lines.

Removing the if statement such that the conditional block always runs appears to fix it. It'll include indentation for empty lines, though I'd personally prefer that anyway.

can't stringify assoc arrays

Input 1:

[1 => 'foo', 3 => 'bar']

Output 1:

[
  null
  foo
]

Input 2

['foo' => 'foo', 'bar' => 'bar']

Output 2

[
  null
  null
]

PHP 5.6 and 7.0 EOL

PHP versions 5.6 and 7.0 are officially unsupported now. Should we stop supporting them as well?

In my PR #19, I made some changes to be compatible with the latest versions of PHP and phpunit, but it broke PHP 7.0 and 5.6 compatibility. It would be easier overall to stop supporting the older versions, but I don't know, is anyone still using this library with an old PHP version?

Cirillic chars in comments breaks script

Throws different errors...

Fatal error: Uncaught HJSON\HJSONException: End of input while parsing an array (did you forget a closing ']'?) at line 19, 30 >>>9,

{ :0 } causes Fatal Error

{
  :0
}

causes Fatal error: Cannot access empty property in .../src/HJSON/HJSONParser.php on line 204 instead of a exception with message Error: Found ':' but no key name

Can't install with composer

PS C:\xampp\htdocs\ulicms> composer require HJSON/HJSON


  [InvalidArgumentException]
  Could not find package HJSON/HJSON at any version for your minimum-stability (stable). Check the package spelling or
   your minimum-stability

I tried this but got the same error

{
	"minimum-stability" : "dev"
}

Disable Hash (#) comments

Hi, could you please provide an option to completely disable using hash (#) as a special symbol for comments?

'#' is a widespread symbol among the web and it is not convenient to enclose a string in quotes should it start with hash.

Thanks.

Parse failed with "0" char in multiline string

Hi,
Cannot have any kind and anywhere the "0" (zero) char in a multiline string. it does give me each time:
HJSONException: Bad multiline string at line x, y

Other "numbers" are working fine :-)
Thanks

UTF8

Cant use danish characters: Æ, Ø and Å.

UTF-8 in multiline strings bug

This example code:

$hjsonParser->parse(
	'{
		content:
			\'\'\'
			←→±≠Я
			\'\'\'
	}'
);

Throws:

Bad multiline string at line 5, 1 >>> ''' } ...

Contributor Wanted!

The PHP implementation of Hjson was kindly contributed by @iainhallam and @jawb.

As they are occupied elsewhere we are in need of a contributor. If you know PHP and would like to help out please let us know!

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.