cancel
Showing results for 
Search instead for 
Did you mean: 

Transform JSON to Ndjson

iambiswa25
New Contributor II

Hi,
I am getting JSON from my SQL Server - Select snap I want to convert it into NDJSON to push the data into ElasticSearch
example:-
the data from SQL server:
[
{
“Id”: “1”,
“Type”: “student”,
“Name”: “s one”,
“Age”: 27
},
{
“Id”: “2”,
“Type”: “teacher”,
“Name”: “t one”,
“Age”: 40
},
{
“Id”: “3”,
“Type”: “student”,
“Name”: “s two”,
“Age”: 16
},
{
“Id”: “4”,
“Type”: “teacher”,
“Name”: “t two”,
“Age”: 27
}
]
Format which ElasticSearch accept
{ “index” : { “_index”: “schoolindex”} }
{“Id”:“1”,“Type”:“student”,“Name”:“s one”,“Age”:27}
{ “index” : { “_index”: “schoolindex”} }
{“Id”:“2”,“Type”:“teacher”,“Name”:“t one”,“Age”:40}
{ “index” : { “_index”: “schoolindex”} }
{“Id”:“3”,“Type”:“student”,“Name”:“s two”,“Age”:16}
{ “index” : { “_index”: “schoolindex”} }
{“Id”:“4”,“Type”:“teacher”,“Name”:“t two”,“Age”:27}

which will be the best way to achieve the required format?
Any help will be greatly appreciated
Thank you

3 REPLIES 3

Abhishek_Soni37
Contributor

Hi @iambiswa25,

Please try this pipeline to get the desired o/p.
image

Pipeline:
JSON-to_NdJSON.slp (6.2 KB)

Let me know if it works.

Cheers 🙂

iambiswa25
New Contributor II

Hi Thanks for your response
I’ve done that without using Script
uploading here if anyone need
json to ndjson_2023_06_19.slp (7.9 KB)

Great solution,

I assumed that you need them as separate documents, not as a string.

Thanks for sharing 🙂