cancel
Showing results for 
Search instead for 
Did you mean: 

How to add text inside json property names, without knowing what properties are there?

DMG
New Contributor

I am getting a json input with a huge number of properties, and a variable structure so we don't know the properties beforehand.

I need to add a prefix to each property name, except when the property name starts with the @ character.

For example, for a possible input that starts like this...

[
{
"TopElement": {
"@url": "https://www.google.com",
"Ver": "2.1.4",

I need to end up with the following:

[
{
"prefix:TopElement": {
"@url": "https://www.google.com",
"prefix:Ver": "2.1.4",

where the prefix "prefix:" has been added to all JSON property names (but not the values) unless they started with "@"-

This would be a piece of cake to do in programming languages, but can it be done in SnapLogic?

Note that the json is derived from an input XML file, so json properties starting with @ are resulting from XML attributes. If there is a way to add the "prefix:" to all XML elements even before converting to json, then it would be even better. The purpose of the pipeline is to process/adjust/enrich the XML file, so the output of the pipeline will be again an XML file, so that "prefix:" could be as well added at the end, either on a json document (before formatting to XML) or the already formatted XML document. 

0 REPLIES 0