Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
edited tags
Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k
title, reword
Source Link
thanasisp
  • 8.5k
  • 2
  • 29
  • 40

how How to create json filesend with curl JSON from another curl command output

I new to json and I want to create oneget JSON with curl command, so so with below command I am getting output:

nowNow i want to store this output as json file so I copied it in file adnand gave extension as .json.json

butBut when i try to put with curl I am getting below error

butBut when i run below command with same json format directclydirectly it works,

what iWhat I want is store curl GET command output as valid json which I can use in curl PUT,

I am new to this and i tried several options with jq as well but that also didntdidn't workd for me.

how to create json file with curl command output

I new to json and I want to create one with curl command, so with below command I am getting output

now i want to store this output as json file so I copied it in file adn gave extension as .json

but when i try to put with curl I am getting below error

but when i run below command with same json format directcly it works,

what i want is store curl GET command output as valid json which I can use in curl PUT,

I am new to this and i tried several options with jq as well but that also didnt workd for me.

How to send with curl JSON from another curl command output

I want to get JSON with curl command, so with below command I am getting output:

Now i want to store this output as json file so I copied it in file and gave extension as .json

But when i try to put with curl I am getting below error

But when i run below command with same json format directly it works,

What I want is store curl GET command output as valid json which I can use in curl PUT,

I am new to this and i tried several options with jq as well but that also didn't workd for me.

Source Link
Samurai
  • 95
  • 2
  • 10

how to create json file with curl command output

I new to json and I want to create one with curl command, so with below command I am getting output

curl -GET http://localhost:9200/oldindex/_mapping?pretty
{
  "gl-events_1" : {
    "mappings" : {
      "message" : {
        "dynamic" : "false",
        "dynamic_templates" : [
          {
            "fields" : {
              "path_match" : "fields.*",
              "mapping" : {
                "doc_values" : true,
                "index" : true,
                "type" : "keyword"
              }
            }
          }
        ],
        "properties" : {
          "alert" : {
            "type" : "boolean"
          },
          "event_definition_id" : {
            "type" : "keyword"
          },
          "event_definition_type" : {
            "type" : "keyword"
          },
          "fields" : {
            "type" : "object",
            "dynamic" : "true"
          },
          "id" : {
            "type" : "keyword"
          },
          "key" : {
            "type" : "keyword"
          },
          "key_tuple" : {
            "type" : "keyword"
          },
          "message" : {
            "type" : "text",
            "norms" : false,
            "fields" : {
              "keyword" : {
                "type" : "keyword"
              }
            },
            "analyzer" : "standard"
          },
          "origin_context" : {
            "type" : "keyword"
          },
          "priority" : {
            "type" : "long"
          },
          "source" : {
            "type" : "keyword"
          },
          "source_streams" : {
            "type" : "keyword"
          },
          "streams" : {
            "type" : "keyword"
          },
          "timerange_end" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          },
          "timerange_start" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          },
          "timestamp" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          },
          "timestamp_processing" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          },
          "triggered_jobs" : {
            "type" : "keyword"
          }
        }
      }
    }
  }
}

now i want to store this output as json file so I copied it in file adn gave extension as .json

but when i try to put with curl I am getting below error

curl -X PUT http://localhost:9200/new_good -H 'Content-Type: application/json' -d  sampl.json
{"error":{"root_cause":[{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}],"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"},"status":500}

but when i run below command with same json format directcly it works,

curl -X PUT \
http://localhost:9200/new_good \
-H 'Content-Type: application/json' \
-d '{"mappings" : {
      "message" : {
        "dynamic_templates" : [
          {
            "internal_fields" : {
              "match" : "gl2_*",
              "match_mapping_type" : "string",
              "mapping" : {
                "type" : "keyword"
              }
            }
          },
          {
            "store_generic" : {
              "match_mapping_type" : "string",
              "mapping" : {
                "type" : "keyword"
              }
            }
          }
        ],
        "properties" : {
          "LoggerName" : {
            "type" : "keyword"
          },
          "MessageParam0" : {
            "type" : "keyword"
          },
          "MessageParam1" : {
            "type" : "long"
          },
          "MessageParam2" : {
            "type" : "keyword"
          },
          "MessageParam3" : {
            "type" : "keyword"
          },
          "MessageParam4" : {
            "type" : "keyword"
          },
          "MessageParam5" : {
            "type" : "keyword"
          },
          "MessageParam6" : {
            "type" : "keyword"
          },
          "MessageParam7" : {
            "type" : "keyword"
          },
          "MessageParam8" : {
            "type" : "keyword"
          },
          "Severity" : {
            "type" : "keyword"
          },
          "SourceClassName" : {
            "type" : "keyword"
          },
          "SourceMethodName" : {
            "type" : "keyword"
          },
          "SourceSimpleClassName" : {
            "type" : "keyword"
          },
          "StackTrace" : {
            "type" : "keyword"
          },
          "Thread" : {
            "type" : "keyword"
          },
          "Time" : {
            "type" : "keyword"
          },
          "facility" : {
            "type" : "keyword"
          },
          "full_message" : {
            "type" : "text",
            "analyzer" : "standard"
          },
          "gl2_accounted_message_size" : {
            "type" : "long"
          },
          "gl2_message_id" : {
            "type" : "keyword"
          },
          "gl2_processing_timestamp" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          },
          "gl2_receive_timestamp" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          },
          "gl2_remote_ip" : {
            "type" : "keyword"
          },
          "gl2_remote_port" : {
            "type" : "long"
          },
          "gl2_source_input" : {
            "type" : "keyword"
          },
          "gl2_source_node" : {
            "type" : "keyword"
          },
          "level" : {
            "type" : "long"
          },
          "message" : {
            "type" : "text",
            "analyzer" : "standard"
          },
          "source" : {
            "type" : "text",
            "analyzer" : "analyzer_keyword",
            "fielddata" : true
          },
          "streams" : {
            "type" : "keyword"
          },
          "timestamp" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss.SSS"
          }
        }
      }
    }
  }
}'

what i want is store curl GET command output as valid json which I can use in curl PUT,

curl get > some.json
curl put -d some.json 

I am new to this and i tried several options with jq as well but that also didnt workd for me.

Please guide me here.

Regards SAM