{"id":667182,"date":"2020-07-20T09:40:46","date_gmt":"2020-07-20T16:40:46","guid":{"rendered":"https:\/\/www.microsoft.com\/en-us\/research\/?post_type=msr-project&p=667182"},"modified":"2022-04-19T15:09:26","modified_gmt":"2022-04-19T22:09:26","slug":"prose-json-transformation","status":"publish","type":"msr-project","link":"https:\/\/www.microsoft.com\/en-us\/research\/project\/prose-json-transformation\/","title":{"rendered":"PROSE – Json Transformation"},"content":{"rendered":"
Transformation.Json<\/strong> transforms the structure of Json using input\/output examples.<\/p>\n The Usage page and the Sample Project (opens in new tab)<\/span><\/a> illustrate the API usage.<\/p>\n Given an example to transform this input Json:<\/p>\n into this output Json:<\/p>\n Transformation.Json<\/strong> will generate a program to perform the same transformation given any other similar and larger input Json. For example, the learned program transforms this input:<\/p>\n into this output:<\/p>\n Transformation.Json transforms the structure of Json using input\/output examples.<\/p>\n","protected":false},"featured_media":674232,"template":"","meta":{"msr-url-field":"","msr-podcast-episode":"","msrModifiedDate":"","msrModifiedDateEnabled":false,"ep_exclude_from_search":false,"_classifai_error":"","footnotes":""},"research-area":[13556,13554,13560],"msr-locale":[268875],"msr-impact-theme":[],"msr-pillar":[],"class_list":["post-667182","msr-project","type-msr-project","status-publish","has-post-thumbnail","hentry","msr-research-area-artificial-intelligence","msr-research-area-human-computer-interaction","msr-research-area-programming-languages-software-engineering","msr-locale-en_us","msr-archive-status-active"],"msr_project_start":"","related-publications":[],"related-downloads":[],"related-videos":[],"related-groups":[],"related-events":[],"related-opportunities":[],"related-posts":[],"related-articles":[],"tab-content":[{"id":0,"name":"Usage","content":"The main entry point is Example Transformation<\/h2>\n
\r\n{\r\n \"datatype\": \"local\",\r\n \"data\": [\r\n {\r\n \"Name\": \"John\",\r\n \"status\": \"To Be Processed\",\r\n \"LastUpdatedDate\": \"2013-05-31 08:40:55.0\"\r\n },\r\n {\r\n \"Name\": \"Paul\",\r\n \"status\": \"To Be Processed\",\r\n \"LastUpdatedDate\": \"2013-06-02 16:03:00.0\"\r\n }\r\n ]\r\n}\r\n<\/pre>\n
\r\n[\r\n {\r\n \"John\" : \"To Be Processed\"\r\n },\r\n {\r\n \"Paul\" : \"To Be Processed\"\r\n }\r\n]\r\n<\/pre>\n
\r\n{\r\n \"datatype\": \"local\",\r\n \"data\": [\r\n {\r\n \"Name\": \"John\",\r\n \"status\": \"To Be Processed\",\r\n \"LastUpdatedDate\": \"2013-05-31 08:40:55.0\"\r\n },\r\n {\r\n \"Name\": \"Paul\",\r\n \"status\": \"To Be Processed\",\r\n \"LastUpdatedDate\": \"2013-06-02 16:03:00.0\"\r\n },\r\n {\r\n \"Name\": \"Alice\",\r\n \"status\": \"Finished\",\r\n \"LastUpdatedDate\": \"2013-07-02 12:04:00.0\"\r\n }\r\n ]\r\n}\r\n<\/pre>\n
\r\n[\r\n {\r\n \"John\" : \"To Be Processed\"\r\n }, \r\n { \r\n \"Paul\" : \"To Be Processed\"\r\n }, \r\n { \r\n \"Alice\" : \"Finished\"\r\n } \r\n]\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"
Session<\/code> class\u2019s
Learn()<\/code> method, which returns a
Program<\/code> object. The
Program<\/code>\u2019s key method is
Run()<\/code> that executes the program on an input Json to obtain the transformed output Json.\r\n\r\nOther important methods are
Serialize()<\/code> and
Deserialize()<\/code> to serialize and deserialize
Program<\/code> object.\r\n\r\nThe Sample Project<\/a> illustrates our API usage.\r\n
Basic Usage<\/h2>\r\nThe following snippet illustrates a learning session to generate a Json transformation program from the example:\r\n\r\n[code autolinks=\"true\" highlight=\"\"]\r\n\/\/ The training input file, which is a small prefix of the input file.\r\nJToken trainInput = JToken.Parse(@\"\r\n{\r\n \"\"datatype\"\": \"\"local\"\",\r\n \"\"data\"\": [\r\n {\r\n \"\"Name\"\": \"\"John\"\",\r\n \"\"status\"\": \"\"To Be Processed\"\",\r\n \"\"LastUpdatedDate\"\": \"\"2013-05-31 08:40:55.0\"\"\r\n },\r\n {\r\n \"\"Name\"\": \"\"Paul\"\",\r\n \"\"status\"\": \"\"To Be Processed\"\",\r\n \"\"LastUpdatedDate\"\": \"\"2013-06-02 16:03:00.0\"\"\r\n }\r\n ]\r\n}\");\r\n\r\n\/\/ The training output file, which is the desired output for the training input.\r\nJToken trainOutput = JToken.Parse(@\"\r\n[\r\n {\r\n \"\"John\"\" : \"\"To Be Processed\"\"\r\n },\r\n {\r\n \"\"Paul\"\" : \"\"To Be Processed\"\"\r\n }\r\n]\");\r\n\r\nvar session = new Session();\r\nsession.Constraints.Add(new Example(trainInput, trainOutput));\r\nProgram program = session.Learn();[\/code]\r\n\r\n
Serializing\/Deserializing a Program<\/h2>\r\nThe
Transformation.Json.Program.Serialize()<\/code> method serializes the learned program to a string.\r\nThe
Transformation.Json.Loader.Instance.Load()<\/code> method deserializes the program text to a program.\r\n\r\n[code autolinks=\"true\" highlight=\"\"]\r\n\/\/ program was learned previously\r\nstring progText = program.Serialize();\r\nProgram loadProg = Loader.Instance.Load(progText);[\/code]\r\n\r\n
Executing a Program<\/h2>\r\nUse the
Run()<\/code> method to obtain the transformed Json output:\r\n\r\n[code autolinks=\"true\" highlight=\"\"]\r\nJToken input = JToken.Parse(@\"\r\n{\r\n \"\"datatype\"\": \"\"local\"\",\r\n \"\"data\"\": [\r\n {\r\n \"\"Name\"\": \"\"John\"\",\r\n \"\"status\"\": \"\"To Be Processed\"\",\r\n \"\"LastUpdatedDate\"\": \"\"2013-05-31 08:40:55.0\"\"\r\n },\r\n {\r\n \"\"Name\"\": \"\"Paul\"\",\r\n \"\"status\"\": \"\"To Be Processed\"\",\r\n \"\"LastUpdatedDate\"\": \"\"2013-06-02 16:03:00.0\"\"\r\n },\r\n {\r\n \"\"Name\"\": \"\"Alice\"\",\r\n \"\"status\"\": \"\"Finished\"\",\r\n \"\"LastUpdatedDate\"\": \"\"2013-07-02 12:04:00.0\"\"\r\n }\r\n ]\r\n}\");\r\n\r\nJToken output = program.Run(input);[\/code]\r\n\r\nOutput is:\r\n\r\n[code autolinks=\"true\" highlight=\"\"]\r\n[\r\n {\r\n \"John\" : \"To Be Processed\"\r\n },\r\n {\r\n \"Paul\" : \"To Be Processed\"\r\n },\r\n {\r\n \"Alice\" : \"Finished\"\r\n }\r\n][\/code]\r\n"}],"slides":[],"related-researchers":[{"type":"user_nicename","display_name":"Vu Le","user_id":39174,"people_section":"Section name 0","alias":"levu"}],"msr_research_lab":[],"msr_impact_theme":[],"_links":{"self":[{"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/msr-project\/667182"}],"collection":[{"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/msr-project"}],"about":[{"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/types\/msr-project"}],"version-history":[{"count":4,"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/msr-project\/667182\/revisions"}],"predecessor-version":[{"id":789851,"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/msr-project\/667182\/revisions\/789851"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/media\/674232"}],"wp:attachment":[{"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/media?parent=667182"}],"wp:term":[{"taxonomy":"msr-research-area","embeddable":true,"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/research-area?post=667182"},{"taxonomy":"msr-locale","embeddable":true,"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/msr-locale?post=667182"},{"taxonomy":"msr-impact-theme","embeddable":true,"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/msr-impact-theme?post=667182"},{"taxonomy":"msr-pillar","embeddable":true,"href":"https:\/\/www.microsoft.com\/en-us\/research\/wp-json\/wp\/v2\/msr-pillar?post=667182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}