Comments (10)
Clearly there is an issue with the actual JSON but do you care whether the output is formatted, give that an IDE or other tool can format JSON to make it more readable when that is required?
from json-csv.
No, formatting is not a problem actually, just setting the encoding option in the end like below will also take care of it.
$csv->setConversionKey('options', JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
from json-csv.
Is it safe to assume that the JSON key names in the original input will never contain the underscore character? Otherwise I don't think the can be fully resolved by replacing convertAndSave()?
from json-csv.
Perhaps the library could be modified so that users can specify their own delimiter char/string for joining / splitting the csv column names, based on their knowledge of the json they are passing in? The potential issue with this is what characters it is acceptable to put into CSV column names, although I don't think there is a definitive specification for that.
from json-csv.
This is a great question, and I have not thought about it before actually. I think instead of forcing to join with underscore, developer should decide what operator will be used.
Maybe, this line can be changed like below.
$result = array_merge($result, $this->flatten($value, $prefix . $key . $this->conversion['join']));
from json-csv.
Great minds think alike ;0)
from json-csv.
This was funny and impressive actually :)
from json-csv.
I'll have a look at fixing this, if that's ok?
from json-csv.
Sure, it will be great, thanks.
from json-csv.
As per the comments on my pull request: I've implemented changes to get the output of csv->json to match the input to json->csv. The result is a significant improvement but there are still issues which I don't think can be resolved without changing the conversion from json to csv, or at least without further consideration.
-
Previously, the json output represented all values as strings, wrapped in double quotes. As the example input above contains numeric values, along with most of the other test data, this resulted in a mismatch between the input and output json. I have resolved this by adding a 'numbers' conversion option which defaults to 'strings' but when set to 'numbers' causes all numeric strings to be converted to numeric types. This could still result in mis-matching input / output json where:
a) input contains numeric f.p. values with 0 fractional value, e.g. 6.0 is output as 6
b) input contains a mix of numbers and numeric strings -
With the stats data, the name of each object from the stats.json file is lost when it is converted to csv, e.g. "kemal-kilicdaroglu" and "muharrem-ince". This is consistent with the stored stats.csv test file, which does not contain these values. Since these values are not in the csv at all I can't even consider how to reinstate them into the output json to make it match the input. A related issue is that the outer braces are then {} where they should be [].
-
With the stats data the "avg" values from the input json are rounded to fewer digits during the json to csv conversion, which means that it is not possible for the values in the output json to match.
from json-csv.
Related Issues (13)
- Implement a Better Conversion Method for JSON to CSV HOT 1
- Library fails on phpstan level 5
- Can't convert JSON file HOT 2
- Allow conversion of a Json string as well instead of just of Json files HOT 1
- Allow conversion from strings
- Allow Conversion From JSON/CSV Strings HOT 1
- Add Github workflow HOT 2
- Test JSON to CSV Conversion
- Create More Tests with Complex Data
- Delimiter HOT 5
- Value as index?
- Is this production ready? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-csv.