JSON -> CSV: JSON documents with top-level list element... What to list?
Created by: JontuKontar
Reference JSON code:
{
"d": {
"__type": "ThisIsATest.Something.Seller.Models.PriceResult",
"PartPriceDescriptions": [{
"PartNumber":"25834953",
"Description":"GRILLE",
"L":443.3300,
"T":332.5000,
"FL":"$443.33",
"FT":"$332.50"
},{
"PartNumber":"2565956",
"Description":"REGULATOR",
"L":164.7600,
"T":115.3300,
"FL":"$164.76",
"FT":"$115.33"
}],
"QuoteId": "430663",
"Errors": null,
"TotalPrice": "$400.19"
}
}
Command Used:
in2csv -f json -v [JSON Document]
Error Code Short:
Only JSON documents with a top-level list element are able to be converted (or a top-level dictionary if specified.
Error Code Long (-v):
Traceback (most recent call last):
File "/usr/local/bin/in2csv", line 9, in <module>
load_entry_point('csvkit==0.9.0', 'console_scripts', 'in2csv')()
File "/Library/Python/2.7/site-packages/csvkit/utilities/in2csv.py", line 82, in launch_new_instance
utility.main()
File "/Library/Python/2.7/site-packages/csvkit/utilities/in2csv.py", line 76, in main
data = convert.convert(self.input_file, filetype, **kwargs)
File "/Library/Python/2.7/site-packages/csvkit/convert/__init__.py", line 40, in convert
return json2csv(f, key, **kwargs)
File "/Library/Python/2.7/site-packages/csvkit/convert/js.py", line 45, in json2csv
raise TypeError('When converting a JSON document with a top-level dictionary element, a key must be specified.')
TypeError: When converting a JSON document with a top-level dictionary element, a key must be specified.
Question/Issue:
Thus far, I have tried almost everything except whatever this error code is looking for and I'm running out of possibilities to try. I have attempted to use -k d
, -k d/PartPriceDescriptions
, and a variety of others with no success. The error code is very terse and the supplementary documentation isn't much more detailed about the solutions for this particular error. What should I be doing?
FYI: In the end, I'm looking to return PartNumber:
,Description:
, L
& T
, to be returned in the CSV file.