{{ transformations:ModifyJsonAction.png}} ======MODIFY JSON====== Category: Transform / Web \\ \\ =====Description===== This action modifies aspects of a [[https://en.wikipedia.org/wiki/JSON|JSON]] object. Commands this action can run are: Change property value, Add property, Delete property, Rename property, and Reformat JSON. \\ =====Action settings===== ^Setting ^Description ^ |Column|Select the column that contains the JSON to be modified.| |Command|Select the modification to run on the selected JSON. Options: //Change property value//, //Add property//, //Delete property//, //Rename property//, or //Format JSON//. See below for the details of each command.| |If the node doesn't exist| Choose how EasyMorph will handle cases when the selected node doesn't exist in the dataset. Options: //Fail// (the workflow halts execution with a warning) or //Ignore// (the workflow continues).| \\ ====Change property value settings==== Description: Changes the value of the select JSON path (key). ^Setting^ Description ^ |JSON Path|Select the path/key to change the value of.| |Replace with*|Enter the value to be inserted.| |The inserted values are dates|Check this option //on// if the values are dates.| * Setting can be specified using a [[:parameters|parameter]].\\ \\ ====Add property options==== Description: Adds a new property under the selected Parent node. ^Option^ Description ^ |Parent|Select the node to insert the new property under.| |Node name*|Enter the name of the new property.| |Node value*|Enter the value of the new property.| |The inserted values are dates|Check this option //on// if the values are dates.| * Setting can be specified using a [[:parameters|parameter]].\\ \\ ====Delete property options==== Description: Removes a property from the JSON in the selected column. ^Option^ Description ^ |JSON Path|Select the node to remove the property from.| \\ ====Rename property options==== Description: Renames a property in the selected JSON path. ^Option^ Description ^ |JSON Path|Select the path to be renamed.| |New name|Enter the new name of the selected path.| \\ ====Format JSON options==== Description: Converts the format of the JSON text from a single-cell string to a tree structure, or the reverse. ^Option^ Description ^ |Make readable|This option converts the JSON from a single-cell text value to a more readable nested structure.| |Minimize size|This option converts the JSON from a nested structure to a single-cell text value.| \\ =====Remarks===== Wildcards like "$" (for root node), and "[*]" (for an array) can be used where JSON Paths and nodes need to be selected/entered. \\ =====Examples===== ====Example #1==== >Change property value: Change the "name" property's value from "Doug" to "Alex". ===Before (source table)=== { "name":"Doug", "id":7, "dept":"Accounting" } ===After (result table)=== { "name":"Alex", "id":7, "dept":"Accounting" } ===Action parameters=== >JSON Path is "name" >Replace with "Alex" >If the node doesn't exist: Fail \\ ====Exmaple #2==== >Add property: Add the new node "age". ===Before (source table)==== { "name":"Doug", "id":7, "dept":"Accounting" } ===After (result table)=== { "name":"Doug", "id":7, "dept":"Accounting", "age":50 } ===Action parameters=== >Parent: $ (root node) >Node name: age >Node value: 50 >If the parent node doesn't exist: Fail \\ ====Example #3==== >Delete property: Remove the "id" property. ===Before (source table)=== { "name":"Doug", "id":7, "dept":"Accounting" } ===After (result table)=== { "name":"Doug", "dept":"Accounting" } ===Action parameters=== > JSON Path: id >If the node doesn't exist: Fail \\ ====Example #4==== >Rename property: Rename the "id" property to "ident". ===Before (source table)=== { "name":"Doug", "id":7, "dept":"Accounting" } ===After (result table)=== { "name":"Doug", "ident":7, "dept":"Accounting" } ===Action parameters=== > JSON Path: id > Replace with: ident >If the node doesn't exist: Fail \\ ====Example #5==== >Format JSON (minimize size): Consolidate the JSON structure into a single line. ===Before (source table)=== { "name":"Doug", "id":7, "dept":"Accounting" } ===After (result table)=== {"name":"Doug","ident":7,"dept":"Accounting"} ===Action parameters=== > Minimize size \\ ====Example #6==== >Format JSON (Make readable): Expand the single-line JSON into a multi-line format. ===Before (source table)=== {"name":"(insert name)","ident" 7,"dept":"Accounting"} ===After (result table)=== { "name":"Doug", "id":7, "dept":"Accounting" } ===Action parameters=== > Make readable \\ =====Community examples===== * [[https://community.easymorph.com/t/example-constructing-json/1279/5|Community example: Constructing JSON]] \\ ===== See also ===== * [[transformations:extractjson|Extract JSON properties]] * [[transformations:parsejson|Parse JSON]] * [[transformations:splitjsonarray|Split JSON array]] * [[syntax:functions:isjson|Functions: IsJson()]]