0

I want to import data on JSON file to PostgreSQL. But, i want to use bash script to do that. Name of the JSON file will represent of name of the table in PostgrSQL. And I have a few JSON to be imported into PostgreSQL. How to do that in bash script? I am using osx.

Please help me.

Here is the example of my JSON File.

[
    {
        "id": "101",
        "name": "User Registered",
        "description": "User has been registered. This is the first status after register.",
        "created_at": "2017-11-25 15:41:28",
        "updated_at": "2017-11-25 15:41:28"
    },
    {
        "id": "102",
        "name": "User active",
        "description": "User is active. She/He has been confirm it by activation code that sent through email",
        "created_at": "2017-11-25 15:41:28",
        "updated_at": "2017-11-25 15:41:28"
    },
    {
        "id": "103",
        "name": "User deleted",
        "description": "User request to delete her/his account",
        "created_at": "2017-11-25 15:41:28",
        "updated_at": "2017-11-25 15:41:28"
    },
    {
        "id": "104",
        "name": "User banned",
        "description": "User get banned for some reason.",
        "created_at": "2017-11-25 15:41:28",
        "updated_at": "2017-11-25 15:41:28"
    }
]
  • @janos The OP has stated as clearly as possible that this is partly to do with bash and you've marked it as duplicate with a completely non-bash question. – Philip Couling Nov 26 '17 at 09:26
  • @PhilipCouling erm... The other question is non-bash, but I don't see how that's relevant. It's a postgresql question, as this, with a postgresql solution, that looks applicable to me. I don't mark questions as dupes easily, in this case I had no doubt. If you think that's a mistake, I'm open to your arguments, if you can convince me that this is not a duplicate, I'll be happy to vote to reopen. – janos Nov 26 '17 at 09:31
  • @janos The OP needs to be told about `<<` and how to use it to pipe dinamic scripts into postgresql. – Philip Couling Nov 26 '17 at 09:32
  • @PhilipCouling does he need? You assume he does, but don't know if he does or not. In the other question, we have much the same kind of JSON, the same kind of inexperienced user, and it looks to have worked out just fine. – janos Nov 26 '17 at 09:35
  • @janos I'm just taking the OP's question on face value. They've made it pretty clear "they want to do this in bash". That alone suggests they are unable to get from this being a bash question to a postgresql question. – Philip Couling Nov 26 '17 at 09:37
  • @PhilipCouling I see your line of reasoning, and that it's different from mine. With your reopen vote, the question is in the review queue now, so other users who agree with you or a moderator can get it reopened. I'll circle back to see if that happens, to know that I've been proven wrong. – janos Nov 26 '17 at 10:22

0 Answers0