Git Product home page Git Product logo

json2php's Introduction

Daniel's github stats

json2php's People

Contributors

bdryanovski avatar bitdeli-chef avatar brodanoel avatar daniel-zahariev avatar ksky521 avatar noahtallen avatar sumotto avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

json2php's Issues

Incorrect handling of arrays with gaps

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

https://3v4l.org/KKbIJ

Best would be treat arrays like objects.

Improve usage documentation

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?

Custom printer support for adding spaces

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 :)

Support short array syntax via pretty printing

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?

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.