daniel-zahariev / json2php Goto Github PK
View Code? Open in Web Editor NEWConvert JSON to PHP representation
Convert JSON to PHP representation
Function cannot handle gaps in arrays
import json2php from "json2php";
console.log(json2php([1, , , , , 3]));
Results in:
array(1, , , , , 3)
// Fatal error: Cannot use empty array elements in arrays in /in/KKbIJ on line 3
Best would be treat arrays like objects.
When you say:
json2php([1, 2, 3])
// => array(1, 2, 3)
What is the meaning?
Probably you could say:
var foo = json2php([1, 2, 3])
// foo = 'array(1, 2, 3)'
Because, when you say array(1, 2, 3)
, it sounds... weird... because it's not a string, but, if it's not a string, what is it?
json2php() function return the String that should be evaluated as a PHP script, right?
Hello, I'd like to be able to remove spaces from PHP arrays, or at least for the library to maintain the original spacing. (My motivation being to reduce the output data size in bytes -- dealing with some constraints and large-ish data sets.)
For example:
json2php({"some":1,"data":2});
// Current result: "array('some' => 1, 'data' => 2)"
// spaces are not required:
// "array('some'=>1,'data'=>2)"
edit: this seemed straightforward, so I opened a PR :)
Short array syntax was added to PHP in 5.4 and means you can use []
instead of array()
.
Now that pretty print capability was added via 89082da I'm wondering if we can extend that to also support something like json2php.make({linebreak:'\n', indent:'\t', short: true})
which would export the data with the short array syntax.
What do you think?
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.