ozdemirburak / json-csv Goto Github PK
View Code? Open in Web Editor NEWJSON to CSV and CSV to JSON converters in PHP.
License: MIT License
JSON to CSV and CSV to JSON converters in PHP.
License: MIT License
Hi!
I would like to know if there's a way to set the delimiter to ;
(Excel csv).
When I set 'delimiter' => ';',
instead of 'delimiter' => ',',
in Csv.php, I get false output.
Is there a solution to this?
Edit: In some Windows localizations, a comma is used for the currency decimal, so Windows sets the list separator to ;
.
Cheers!
Adding a workflow to this repository would be great.
As an example you can check this commit:
The library is functional and has performed as expected during initial testing with a set of predefined test cases. However, to ensure its robustness, accuracy, and readiness for a broader release, it's essential to subject it to testing with a diverse range of JSON files.
This testing will aid in identifying any hidden bugs, edge cases, or performance issues that might not have surfaced during initial testing.
If you find any bugs, feel free to fix them.
Version to check: 0.5.0-alpha
Note: There's no need to ask for assignment, just proceed with testing. Also, feel free to add new tests to the tests folder.
In CSV to JSON, would there be a way to set one of the columns as the object index, instead of having the output json indexed by number? Ie. the example from the readme:
[
{
"SepalLength": "5.1",
"SepalWidth": "3.5",
"PetalLength": "1.4",
"PetalWidth": "0.2",
"Name": "Iris-setosa"
},
{
"SepalLength": "7.0",
"SepalWidth": "3.2",
"PetalLength": "4.7",
"PetalWidth": "1.4",
"Name": "Iris-versicolor"
},
{
"SepalLength": "6.3",
"SepalWidth": "3.3",
"PetalLength": "6.0",
"PetalWidth": "2.5",
"Name": "Iris-virginica"
}
]
to
[
"Iris-setosa": {
"SepalLength": "5.1",
"SepalWidth": "3.5",
"PetalLength": "1.4",
"PetalWidth": "0.2",
"Name": "Iris-setosa"
},
"Iris-versicolor": {
"SepalLength": "7.0",
"SepalWidth": "3.2",
"PetalLength": "4.7",
"PetalWidth": "1.4",
"Name": "Iris-versicolor"
},
"Iris-virginica": {
"SepalLength": "6.3",
"SepalWidth": "3.3",
"PetalLength": "6.0",
"PetalWidth": "2.5",
"Name": "Iris-virginica"
}
]
This would make for easier search in large JSON files so that you don't have to loop through each object and look for the Name, rather loop through each object with key Name.
Currently, the package only supports converting from file inputs.
The package needs a new method like fromString(), where users can convert JSON/CSV strings to CSV/JSV strings without input files.
Currently, the package only supports converting from files, an issue mentioned before in #15.
The package needs a new method like fromString(), where users can convert JSON/CSV strings to CSV/JSV strings without input files.
Currently, it is assumed that each object shares the same properties while converting JSON to CSV. So if one object has a property that the other one does not have, then it becomes a major problem.
So one should implement a better conversion method where it would not fail with objects that do not share the same properties.
Example Input:
[
{
"x": 0,
"y": 1
},
{
"y": 0,
"z": 0
}
]
Output: (Wrong)
x | y |
---|---|
0 | 1 |
0 | 0 |
Expected Output: (True)
x | y | z |
---|---|---|
0 | 1 | null |
null | 0 | 0 |
If it is production ready, can you please update the tag/version to be 1.0.0?
If it is not production ready, what are your concerns?
Thanks
Currently, when one uses the output of JSON to CSV conversion as an input of CSV to JSON, one does not get the same input provided in the first place.
Example Scenario:
$csv = (new Json('whatever.json'))->convertAndSave('whatever.csv');
$json = (new Csv('whatever.csv'))->convertAndSave('whatever-new.json');
file_get_contents('whatever.json') === file_get_contents('whatever-new.json');
Here are the input and the output files for the example scenario.
Input: whatever.json
[
{
"name": {
"common": "Turkey"
},
"latlng": [39, 35]
}
]
Output: whatever.csv
name_common | latlng_0 | latlng_1 |
---|---|---|
Turkey | 39 | 35 |
Output: whatever-2.json
[{"name_common":"Turkey","latlng_0":"39","latlng_1":"35"}]
What is expected is a new method when used converts whatever.csv
to whatever.json
again instead of whatever-2.json
.
As the title says. Restricting the conversion to files seems like an artificial, unnecessary limitation.
Probably this package has some bugs that can be identified with new tests. With taking inspiration from the current tests located in CsvTest.php and JsonTest.php files, you may create or modify some tests with more complex data.
What I mean by complex data is nested data like the below one.
{
"a": {
"b": {
"c": 1,
"d": {
"e": [
{
"f": 2,
"g": 3
}
]
}
}
}
}
TLDR: Create new tests to make package fail.
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.