PhenixID

Convert Structured Csv to Json

Version: 1.0

Category: Process

Extended Category: JSON

Action Package: Standard Actions

Description

Convert a CSV value in a session attribute to a JSON value.

Parameter Description Example
CSV Attribute[Mandatory] The name of the session attribute with the CSV value.csvPerson
Result Attribute[Optional] To create a new session attribute with the result, instead of over writing the value in the original attribute, enter a session attribute name.jsonPerson
Result in JSON Array[Optional] If the JSON objects should be placed in a JSON Array (true) or remain as single JSON objects, in a single or multivalue attribute (false). Default: truefalse
Properties Separator[Optional] The separator between the properties. Default: ||
Name and Value Separator[Optional] The separator between the property name and the property value. Default: >>
Multiple Values Separator[Optional] The separator between multiple property values. Default: §§
Marker for non String Values[Optional] The character that marks that a value is not a string value, and should not be surrounded by “. Default: ##

Use Cases

Example 1: Convert a multivalue CSV to a multivalue JSON

Converting a multivalue attribute named csvPersons to a new attribute called jsonPersons, using the default characters. The option “Result in JSON Array” is set to false, so the attribute jsonPersons will be a multivalue attribute, with one JSON object in each value.

csvPersons:

sn>Smith|givenName>Bob§Lee|age>#45|alive>#true|childrenAge>#3§4§7

sn>Clarson|givenName>Susan|age>#48|alive>#true|childrenAge>#4§6

jsonPerson:

{"sn":"Smith","givenName":["Bob","Lee"],"age":45,"alive":true,"childrenAge":[3,4,7]}

{"sn":"Clarson","givenName":"Susan","age":48,"alive":true,"childrenAge":[4,6]}

jsonPerson, pretty formated:

{
  "sn":"Smith",
  "givenName":["Bob","Lee"],
  "age":45,
  "alive":true,
  "childrenAge":[3,4,7]
}

{
  "sn":"Clarson",
  "givenName":"Susan",
  "age":48,
  "alive":true,
  "childrenAge":[4,6]
}

csvPerson:

sn>Smith|givenName>Bob§Lee|age>#45|alive>#true|childrenAge>#3§4§7

Example 2: Convert a multivalue CSV to a JSON array

Converting a multivalue attribute named csvPersons to a new attribute called jsonPersons, using the default characters. The option “Result in JSON Array” is set to true, so the attribute jsonPersons will be a single value attribute containing a JSON array.

csvPersons:

sn>Smith|givenName>Bob§Lee|age>#45|alive>#true|childrenAge>#3§4§7

sn>Clarson|givenName>Susan|age>#48|alive>#true|childrenAge>#4§6

jsonPersons:

[{"sn":"Smith","givenName":["Bob","Lee"],"age":45,"alive":true,"childrenAge":[3,4,7]},{"sn":"Clarson","givenName":"Susan","age":48,"alive":true,"childrenAge":[4,6]}]

jsonPersons, pretty formated:

[
  {
    "sn":"Smith",
    "givenName":["Bob","Lee"],
    "age":45,
    "alive":true,
    "childrenAge":[3,4,7]
  },
  {
    "sn":"Clarson",
    "givenName":"Susan",
    "age":48,
    "alive":true,
    "childrenAge":[4,6]
  }
]

Example 3: Convert a single value CSV to a JSON array

Converting a single value attribute named csvPersons to a new attribute called jsonPersons, using the default characters. The option “Result in JSON Array” is set to true, so the attribute jsonPersons will be a single value attribute containing a JSON array.

csvPersons:

sn>Smith|givenName>Bob§Lee|age>#45|alive>#true|childrenAge>#3§4§7

jsonPersons:

[{"sn":"Smith","givenName":["Bob","Lee"],"age":45,"alive":true,"childrenAge":[3,4,7]}]

jsonPersons, pretty formated:

[
  {
    "sn":"Smith",
    "givenName":["Bob","Lee"],
    "age":45,
    "alive":true,
    "childrenAge":[3,4,7]
  }
]

DISCLAIMER
Information provided in this document is for your information only. PhenixID makes no explicit or implied claims to the validity of this information. Any trademarks referenced in this document are the property of their respective owners.

The origin of this information may be internal or external to PhenixID. PhenixID makes all reasonable efforts to verify this information.

PhenixID - support.phenixid.se