json out element namming problem

Six Stars

json out element namming problem

hello,

thanks to the explaination of the topic

39421#M11049

i've manage to out a json structured like this :

json.png

[
	{
		"key": "1",
		"key_datas": {
			"key_date": "2018-06-30T23:02:00"
		}
	},
	{
		"key": "2",
		"key_datas": {
			"key_date": "1974-06-30T12:30:00"
		}
	},
	{
		"key": "3",
		"key_datas": {
			"key_date": "2006-09-04T11:30:00"
		}
	}
]

but in need to out the "key_date" element as : "date(date_key)"

that mean a full out like this :

[
	{
		"key": "1",
		"key_datas": {
			"date(key_date)": "2018-06-30T23:02:00"
		}
	},
	{
		"key": "2",
		"key_datas": {
			"date(key_date)": "1974-06-30T12:30:00"
		}
	},
	{
		"key": "3",
		"key_datas": {
			"date(key_date)": "2006-09-04T11:30:00"
		}
	}
]

the only ugly solution i've found is to string replace with a tJavarow

String jsonStrReplaced = row3.json;
jsonStrReplaced =StringHandling.CHANGE(jsonStrReplaced, "key_date", "date(key_date)");
output_row.jsonStrReplaced = jsonStrReplaced;

do any one has a smarter solution ?

when i try a to name it in tWriteJsonField, i have a

rg.xml.sax.SAXParseException

Tags (1)
Forteen Stars

Re: json out element namming problem

always possible to find bypass (like You already do), but always better to talk with developers about following standards:

 

http://jsonapi.org/format/#document-member-names

 

The following characters MUST NOT be used in member names:

...
U+0025 PERCENT SIGN, “%”
U+0026 AMPERSAND, “&”
U+0027 APOSTROPHE, “’”
U+0028 LEFT PARENTHESIS, “(“
U+0029 RIGHT PARENTHESIS, “)”
...

 

 

-----------
Six Stars

Re: json out element namming problem

you are really right !!!

but in the true life... that's not always possible :-)

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog