Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 99573

Formatting JSON Data to a single line

$
0
0

I am having some requirements:

  1. Each json data point must be on a single line
  2. Each json data point must be separated by a newline character
  3. Additionally, if possible each data point must be separated by an {"index":{}} statement

I am having roughly 1000 json data points. Here is an example of what three look like:

{
  "str field": "some string",
  "int field": 12345,
  "bool field": True
}{
  "str field": "another string",
  "int field": 42,
  "bool field": False
}{
  "str field": "random string",
  "int field": 3856452,
  "bool field": True
}

But I need it to look like so:

{"index":{}}
{"str field": "some string", "int field": 12345, "bool field": True}
{"index":{}}
{"str field": "another string", "int field": 42, "bool field": False}
{"index":{}}
{"str field": "random string", "int field": 3856452, "bool field": True}

Currently i am using http://jsonviewer.stack.hu/ along with notepad++ to accomplish this but it is not always working properly and struggles with larger datasets. I would prefer not to use a third party website but rather accomplish the same using an IDE such as VS Code or IntelliJ.

If you are familiar with elasticsearch I am essentially formatting the data for bulk indexing operations.

Thank you


Viewing all articles
Browse latest Browse all 99573

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>