JSON Dataset

Post Reply
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

JSON Dataset

Post by gabrielp »

What's the simplest way to take a JSON response and convert it to a data set that Switch can use?
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

JSON Dataset

Post by dkelly »





var jsonString = '{

"glossary": {

"title": "example glossary",

"GlossDiv": {

"title": "S",

"GlossList": {

"GlossEntry": {

"ID": "SGML",

"SortAs": "SGML",

"GlossTerm": "Standard Generalized Markup Language",

"Acronym": "SGML",

"Abbrev": "ISO 8879:1986",

"GlossDef": {

"para": "A meta-markup language, used to create markup languages such as DocBook.",

"GlossSeeAlso": ["GML", XML]

},

"GlossSee": "markup"

}

}

}

}

}';



var parsedObject = eval("(" + jsonString + ")");

s.log(2, parsedObject.glossary.title);
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

JSON Dataset

Post by gabrielp »

Sorry Dwight, I think I was unclear. Yours is a little more concise but I have been doing something similar:



var objJSON = eval("(function(){return " + JSONString + ";})()");



What I'm after is trying to take a big JSON object and easily get it into Switch metadata somehow. Right now, I have to do something like you suggested and above and write each key to Private Data. I'm wondering how you could take a big, complex, JSON object and put it into a Switch dataset somehow so you could reference all of the values in the flow later.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

JSON Dataset

Post by dkelly »

There are many Javascript JSON2XML converters that should work with small modifications to remove unsupported Javascript language features such as 'object.constructor'.
Post Reply