Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C csvkit
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 61
    • Issues 61
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • wireservice
  • csvkit
  • Merge requests
  • !95

fix csvjson utf-8 output, add output option to key json objects with a column name

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/ewheeler/master into master Aug 16, 2011
  • Overview 1
  • Commits 2
  • Pipelines 0
  • Changes 1

Created by: ewheeler

Update csvjson to output utf-8 correctly. Current code will output utf-8 like: "short_name_en": "\u00c5LAND ISLANDS" instead of: "short_name_en": "ÅLAND ISLANDS"

Also add option to output json objects keyed by a column name instead of a list. Currently, csvjson outputs a list of dict-like JSON objects: csvjson -i 2 countries-of-earth.csv

outputs:

[
  {
    "FIFA": "ALD", 
    "Dial": "358", 
    "ITU": " ", 
    "MARC": " ", 
    "is_independent": "Part of FI", 
    "DS": "FIN", 
    "WMO": " ", 
    "GAUL": "1242", 
    "ISO3166-1-numeric": "248", 
    "FIPS": " ", 
    "short_name_fr": "ÅLAND, ÎLES", 
    "ISO3166-1-Alpha-3": "ALA", 
    "IOC": " ", 
    "ISO3166-1-Alpha-2": "AX", 
    "short_name_en": "ÅLAND ISLANDS"
  }, 
  ...
]

The proposed new option accepts a named key (column name) and outputs a single dict-like JSON object where item values are the same dict-like JSON row representations that are currently outputted -- but the item names are the object's values for the given key: csvjson -i 2 -k ISO3166-1-Alpha-2 countries-of-earth.csv

outputs:

{
  "AX": {
    "FIFA": "ALD", 
    "Dial": "358", 
    "ITU": " ", 
    "MARC": " ", 
    "is_independent": "Part of FI", 
    "DS": "FIN", 
    "WMO": " ", 
    "GAUL": "1242", 
    "ISO3166-1-numeric": "248", 
    "FIPS": " ", 
    "short_name_fr": "ÅLAND, ÎLES", 
    "ISO3166-1-Alpha-3": "ALA", 
    "IOC": " ", 
    "ISO3166-1-Alpha-2": "AX", 
    "short_name_en": "ÅLAND ISLANDS"
  }, 
   ...
}
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/ewheeler/master