0

Since yesterday, I am sitting fast to get it as .csv. but fails.

Tried with below commands, but failss with following error:

jq: error (at j.json:70): object ({"DCS_CCH_A...) is not valid in a csv row

jq -r '[.[]] | @csv' j.json

Tried also another way, still fails, with followingerror:

jq: error (at j.json:1): Cannot iterate over string ("{")
jq: error (at j.json:2): Cannot iterate over string ("    \"vehi...)
jq: error (at j.json:3): Cannot iterate over string ("        \"...).


jq -Rr '[.[]] | @csv' j.json

How I can convert it as csv? OS is Linux Ubuntu

This is my JSON file:

{
  "vehicleStatus": {
    "DCS_CCH_Activation": "NA",
    "DCS_CCH_Ongoing": false,
    "cbsData": [
      {
        "cbsDescription": "Next service due when the stated distance has been covered or by the specified date.",
        "cbsDueDate": "2021-02",
        "cbsRemainingMileage": 18000,
        "cbsState": "OK",
        "cbsType": "OIL"
      },
      {
        "cbsDescription": "Next change due at the latest by the stated date.",
        "cbsDueDate": "2022-03",
        "cbsState": "OK",
        "cbsType": "BRAKE_FLUID"
      },
      {
        "cbsDescription": "Next visual inspection due when the stated distance has been covered or by the stated date.",
        "cbsDueDate": "2023-02",
        "cbsRemainingMileage": 49000,
        "cbsState": "OK",
        "cbsType": "VEHICLE_CHECK"
      }
    ],
    "chargingLevelHv": 17,
    "chargingStatus": "WAITING_FOR_CHARGING",
    "connectionStatus": "CONNECTED",
    "doorDriverFront": "CLOSED",
    "doorDriverRear": "CLOSED",
    "doorLockState": "SECURED",
    "doorPassengerFront": "CLOSED",
    "doorPassengerRear": "CLOSED",
    "fuelPercent": 54.5,
    "hood": "CLOSED",
    "mileage": 13919,
    "parkingLight": "OFF",
    "position": {
      "heading": 1,
      "lat": 18.3,
      "lon": 84.5,
      "status": "OK"
    },
    "positionLight": "OFF",
    "rearWindow": "INVALID",
    "remainingFuel": 23,
    "remainingRangeElectric": 4,
    "remainingRangeElectricMls": 2,
    "remainingRangeFuel": 260,
    "remainingRangeFuelMls": 161,
    "singleImmediateCharging": false,
    "sunroof": "CLOSED",
    "trunk": "CLOSED",
    "updateReason": "DOOR_STATE_CHANGED",
    "vin": "some_vin",
    "windowDriverFront": "CLOSED",
    "windowDriverRear": "CLOSED",
    "windowPassengerFront": "CLOSED",
    "windowPassengerRear": "CLOSED"
  }
}
Alex
  • 43
  • 1
  • 6

1 Answers1

0

In this question, someone provided a generic JSON to CSV converter using jq. There are several other questions on here that explain more about the mechanics of the process, such as this one.

swmcdonnell
  • 1,381
  • 9
  • 22