Adds comments, makes it nicer to read and avoids comma mistakes.
For details see hjson.github.io.
Hjson for PHP
Home Page: https://hjson.github.io/
License: MIT License
Adds comments, makes it nicer to read and avoids comma mistakes.
For details see hjson.github.io.
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.
@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
Can this be fixed or should we remove builds for PHP <= 5.5?
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.
Input 1:
[1 => 'foo', 3 => 'bar']
Output 1:
[
null
foo
]
Input 2
['foo' => 'foo', 'bar' => 'bar']
Output 2
[
null
null
]
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?
Curious why - will dig in a bit and generate a test file to replicate at the very least.
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: Cannot access empty property in .../src/HJSON/HJSONParser.php on line 204
instead of a exception with message Error: Found ':' but no key name
See hjson/hjson#74
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"
}
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.
{
0: 0
}
When I try parse the code above, I receive this error: Found ':' but no key name (for an empty key name use quotes) at line 2, 4 >>> 0: 0 } ...
. But this hjson code works in https://hjson.org/try.html
my code:
$hjson_parser = new HJSONParser();
try {
$variables = $hjson_parser->parse( $hjson_text );
} catch ( Exception $e ) {
...
}
How can I get arrays instead of objects ?
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
Thank you for a great library.
I found an issue. The string
{products: [
{name:'Knife', price: 2.25},
{name:'Spoon', price: 2.50},
{name:'Fork', price: 2.99},
]}
works when I use http://hjson.org/try.html but not when using this library.
Cant use danish characters: Æ, Ø and Å.
This example code:
$hjsonParser->parse(
'{
content:
\'\'\'
←→±≠Я
\'\'\'
}'
);
Throws:
Bad multiline string at line 5, 1 >>> ''' } ...
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.