{"id":112,"date":"2025-06-13T18:29:31","date_gmt":"2025-06-13T18:29:31","guid":{"rendered":"https:\/\/powerplatformsolutions.net\/?p=112"},"modified":"2025-06-22T10:21:23","modified_gmt":"2025-06-22T10:21:23","slug":"working-with-json-easier-then-you-think","status":"publish","type":"post","link":"https:\/\/powerplatformsolutions.net\/?p=112","title":{"rendered":"Working with JSON &#8211; easier then you think"},"content":{"rendered":"\n<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-8441781ed341d29fae13ebadaf73d600\" style=\"color:#f0e6e6\"><\/h2>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-24e7e595b45390778ff8997ed9ff769e\" style=\"color:#f0e6e6\">I guess we all had cases where we had to store some list of items as a string, which could easily be converted into array and back to string to be saved. That could be names, emails or list of IDs from a list (to make many-to-many relationship, for example). Sounds easy, hey, just concatenate with coma to add and remove item from the string, and just to simple Split() when need to have it as an array&#8230; and after few updates we end up with lots of extra comas \ud83d\ude41  boooooooo<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-9785714e3fbec7386b0ad724d7d7bdc3\" style=\"color:#f0e6e6\">  So all we have to do is to convert the string into array first, than add or remove item in array and convert it back to string. <br>But can we do it in one line? &#8211; sure we can \ud83d\ude42 <br> <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"57\" src=\"https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray1-1024x57.png\" alt=\"\" class=\"wp-image-114\" srcset=\"https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray1-1024x57.png 1024w, https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray1-300x17.png 300w, https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray1-768x42.png 768w, https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray1.png 1139w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-5a20915235afd352ed12a34b5095ed9a\" style=\"color:#f0e6e6\">And here is an action under Add button:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"708\" height=\"41\" src=\"https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray2.png\" alt=\"\" class=\"wp-image-115\" srcset=\"https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray2.png 708w, https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray2-300x17.png 300w\" sizes=\"(max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"38\" src=\"https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray3-1024x38.png\" alt=\"\" class=\"wp-image-116\" srcset=\"https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray3-1024x38.png 1024w, https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray3-300x11.png 300w, https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray3-768x29.png 768w, https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray3.png 1284w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-2af8bb8d1de29a57ba16c77aa4242159\" style=\"color:#f0e6e6\">  And here is how we remove an item (onSelect of trash icon):<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"928\" height=\"34\" src=\"https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray4.png\" alt=\"\" class=\"wp-image-117\" srcset=\"https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray4.png 928w, https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray4-300x11.png 300w, https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray4-768x28.png 768w\" sizes=\"(max-width: 928px) 100vw, 928px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-b05a534a5fa291b40a251f2434eeab7e\" style=\"color:#f0e6e6\">Want to have pure numbers in array values (integers etc)?  &#8211;  No problem:)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"740\" height=\"32\" src=\"https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray5-1.png\" alt=\"\" class=\"wp-image-119\" srcset=\"https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray5-1.png 740w, https:\/\/powerplatformsolutions.net\/wp-content\/uploads\/2024\/09\/StringArray5-1-300x13.png 300w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-e82c53108428334d59e79d7d86455b67\" style=\"color:#f0e6e6\"><br>Its a short one, but took me a while to figure it out <\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I guess we all had cases where we had to store some list of items as a string, which could easily be converted into array and back to string to be saved. That could be names, emails or list of IDs from a list (to make many-to-many relationship, for example). Sounds easy, hey, just concatenate [&hellip;]<\/p>\n","protected":false},"author":85,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-112","post","type-post","status-publish","format-standard","hentry","category-powerapps"],"_links":{"self":[{"href":"https:\/\/powerplatformsolutions.net\/index.php?rest_route=\/wp\/v2\/posts\/112"}],"collection":[{"href":"https:\/\/powerplatformsolutions.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/powerplatformsolutions.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/powerplatformsolutions.net\/index.php?rest_route=\/wp\/v2\/users\/85"}],"replies":[{"embeddable":true,"href":"https:\/\/powerplatformsolutions.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=112"}],"version-history":[{"count":8,"href":"https:\/\/powerplatformsolutions.net\/index.php?rest_route=\/wp\/v2\/posts\/112\/revisions"}],"predecessor-version":[{"id":265,"href":"https:\/\/powerplatformsolutions.net\/index.php?rest_route=\/wp\/v2\/posts\/112\/revisions\/265"}],"wp:attachment":[{"href":"https:\/\/powerplatformsolutions.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/powerplatformsolutions.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/powerplatformsolutions.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}