How to clean this JSON?

Hellooo! im using google Apis to request data from a blog.
I want to be able to acces the content of a post, but in the json file the body of the text is between html code. how can i remove it ? in orden to get only the string ?

"content": "<a href=\"https://www.youtube.com/watch?v=r7OMvBtV0l4\">https://www.youtube.com/watch?v=r7OMvBtV0l4</a>",

i only want the text between " " (youtube links , in this case);

thanks

just to find the link could use
https://processing.org/reference/splitTokens_.html

String test = "<a href=\"https://www.youtube.com/watch?v=r7OMvBtV0l4\">https://www.youtube.com/watch?v=r7OMvBtV0l4</a>";
String[] q = splitTokens(test,"\"");
printArray(q);

shows

[0] "<a href="
[1] "https://www.youtube.com/watch?v=r7OMvBtV0l4"
[2] ">https://www.youtube.com/watch?v=r7OMvBtV0l4</a>"

so q[1] is what you need?

1 Like

EDIT: below is a Processing (Java) answer – didn’t realize this was a p5.js question

The best way to do this reliably is to use the built-in JSONObject or JSONArray, which has setString and getString. That handles all the escaping for you.

JSONObject json;
void setup() {
  json = new JSONObject();
  json.setString("content", "<a href=\"https://www.youtube.com/watch?v=r7OMvBtV0l4\">https://www.youtube.com/watch?v=r7OMvBtV0l4</a>");
  println(json);
  String content = json.getString("content");
  println(content);
  saveJSONObject(json, "inspect.json");
}

What are you parsing from the api? A JSON object or array in a string?

1 Like

this is what i receive from the api. Im in p5.js. what i want is get the text written in the posts. In the best case, i would like to find a way to if there any link to another page (like in the example) conserve the format and conserve the link. but i think thats html?

{  
  "kind":"blogger#postList",
  "nextPageToken":"CgkIChjBrvSvtSwQmp-lor7i559d",
  "items":[  
    {  
      "kind":"blogger#post",
      "id":"152383897114320429",
      "blog":{  
        "id":"6719264076843274138"
      },
      "published":"2018-11-07T05:07:00-08:00",
      "updated":"2018-11-07T05:07:10-08:00",
      "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/dGltZXN0YW1wOiAxNTQxNTk2MDMwMzY1Cm9mZnNldDogLTI4ODAwMDAwCg\"",
      "url":"http://jpvallejo.blogspot.com/2018/11/wassily-kandinsky.html",
      "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/152383897114320429",
      "title":"Wassily Kandinsky",
      "content":"\u003cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003e\nMúsica Visual. Se interesa por la sinestesia y la relación entre color, forma, movimiento y sonido.\u003cbr /\u003e\n\u003cbr /\u003e\n\u003cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003e\n\u003ca href=\"https://1.bp.blogspot.com/-NqlB5nuns9Q/W-LjQo1lR_I/AAAAAAAAFZY/MFTWmx-JYbA0_-rf-psDoHbiltEUNO0YACLcBGAs/s1600/Vassily_Kandinsky%252C_1923_-_Circles_in_a_Circle.jpg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003e\u003cimg border=\"0\" data-original-height=\"682\" data-original-width=\"664\" height=\"640\" src=\"https://1.bp.blogspot.com/-NqlB5nuns9Q/W-LjQo1lR_I/AAAAAAAAFZY/MFTWmx-JYbA0_-rf-psDoHbiltEUNO0YACLcBGAs/s640/Vassily_Kandinsky%252C_1923_-_Circles_in_a_Circle.jpg\" width=\"622\" /\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003e\n\u003ca href=\"https://4.bp.blogspot.com/-DjrkjGYVAbk/W-LjMEXmfRI/AAAAAAAAFZQ/Wver0G16KGcNQ5Gi6BtWo_c1CFGzrXYPwCEwYBhgL/s1600/images%2B%25281%2529.jpeg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003e\u003cimg border=\"0\" data-original-height=\"186\" data-original-width=\"271\" height=\"439\" src=\"https://4.bp.blogspot.com/-DjrkjGYVAbk/W-LjMEXmfRI/AAAAAAAAFZQ/Wver0G16KGcNQ5Gi6BtWo_c1CFGzrXYPwCEwYBhgL/s640/images%2B%25281%2529.jpeg\" width=\"640\" /\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cbr /\u003e\n\u003cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003e\n\u003ca href=\"https://1.bp.blogspot.com/-GkrW9Ma5b9w/W-LjNd9w2uI/AAAAAAAAFZU/K3NO7zg94BoD9cy8OIxrUZ4Y7BNWVycIwCEwYBhgL/s1600/images%2B%25282%2529.jpeg\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003e\u003cimg border=\"0\" data-original-height=\"168\" data-original-width=\"300\" height=\"358\" src=\"https://1.bp.blogspot.com/-GkrW9Ma5b9w/W-LjNd9w2uI/AAAAAAAAFZU/K3NO7zg94BoD9cy8OIxrUZ4Y7BNWVycIwCEwYBhgL/s640/images%2B%25282%2529.jpeg\" width=\"640\" /\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cbr /\u003e\u003c/div\u003e\n",
      "author":{  
        "id":"02116198639170264068",
        "displayName":"juan",
        "url":"https://www.blogger.com/profile/02116198639170264068",
        "image":{  
          "url":"//lh3.googleusercontent.com/zFdxGE77vvD2w5xHy6jkVuElKv-U9_9qLkRYK8OnbDeJPtjSZ82UPq5w6hJ-SA=s35"
        }
      },
      "replies":{  
        "totalItems":"0",
        "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/152383897114320429/comments"
      },
      "labels":[  
        "artistas",
        "Kandinsky",
        "música",
        "obras",
        "sinestesia"
      ]
    },
    {  
      "kind":"blogger#post",
      "id":"2920687298922811470",
      "blog":{  
        "id":"6719264076843274138"
      },
      "published":"2018-11-06T22:58:00-08:00",
      "updated":"2018-11-06T22:58:47-08:00",
      "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/dGltZXN0YW1wOiAxNTQxNTczOTI3MjIwCm9mZnNldDogLTI4ODAwMDAwCg\"",
      "url":"http://jpvallejo.blogspot.com/2018/11/center-for-visual-music.html",
      "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/2920687298922811470",
      "title":"Center for visual Music",
      "content":"\u003cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003e\nhttp://www.centerforvisualmusic.org/\u003c/div\u003e\n",
      "author":{  
        "id":"02116198639170264068",
        "displayName":"juan",
        "url":"https://www.blogger.com/profile/02116198639170264068",
        "image":{  
          "url":"//lh3.googleusercontent.com/zFdxGE77vvD2w5xHy6jkVuElKv-U9_9qLkRYK8OnbDeJPtjSZ82UPq5w6hJ-SA=s35"
        }
      },
      "replies":{  
        "totalItems":"0",
        "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/2920687298922811470/comments"
      },
      "labels":[  
        "cine expandido",
        "música",
        "sinestesia"
      ]
    },
    {  
      "kind":"blogger#post",
      "id":"959873057149996178",
      "blog":{  
        "id":"6719264076843274138"
      },
      "published":"2018-11-06T22:57:00-08:00",
      "updated":"2018-11-06T22:57:28-08:00",
      "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/dGltZXN0YW1wOiAxNTQxNTczODQ4NTUzCm9mZnNldDogLTI4ODAwMDAwCg\"",
      "url":"http://jpvallejo.blogspot.com/2018/11/tarik-barri.html",
      "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/959873057149996178",
      "title":"Tarik Barri",
      "content":"\u003cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003e\n\u003ciframe allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\" frameborder=\"0\" height=\"315\" src=\"https://www.youtube.com/embed/r4tW3mhp9io\" width=\"560\"\u003e\u003c/iframe\u003e\n\n\u003cbr /\u003e\n\u003ciframe allowfullscreen=\"\" frameborder=\"0\" height=\"360\" mozallowfullscreen=\"\" src=\"https://player.vimeo.com/video/222856399\" webkitallowfullscreen=\"\" width=\"640\"\u003e\u003c/iframe\u003e\n\n\u003ca href=\"https://vimeo.com/222856399\"\u003eVersum feat. Lea Fabrikant 2017 (excerpts)\u003c/a\u003e from \u003ca href=\"https://vimeo.com/tarikbarri\"\u003eTarik Barri\u003c/a\u003e on \u003ca href=\"https://vimeo.com/\"\u003eVimeo\u003c/a\u003e.\u003c/div\u003e\n",
      "author":{  
        "id":"02116198639170264068",
        "displayName":"juan",
        "url":"https://www.blogger.com/profile/02116198639170264068",
        "image":{  
          "url":"//lh3.googleusercontent.com/zFdxGE77vvD2w5xHy6jkVuElKv-U9_9qLkRYK8OnbDeJPtjSZ82UPq5w6hJ-SA=s35"
        }
      },
      "replies":{  
        "totalItems":"0",
        "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/959873057149996178/comments"
      },
      "labels":[  
        "artistas",
        "cine expandido",
        "dispositivos",
        "investigación",
        "obras",
        "software",
        "sonido"
      ]
    },
    {  
      "kind":"blogger#post",
      "id":"1922834480471121214",
      "blog":{  
        "id":"6719264076843274138"
      },
      "published":"2018-11-06T17:02:00-08:00",
      "updated":"2018-11-06T17:02:30-08:00",
      "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/dGltZXN0YW1wOiAxNTQxNTUyNTUwMTgzCm9mZnNldDogLTI4ODAwMDAwCg\"",
      "url":"http://jpvallejo.blogspot.com/2018/11/stan-brakhage.html",
      "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/1922834480471121214",
      "title":"Stan Brakhage",
      "content":"\u003cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003e\n\u003ciframe allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\" frameborder=\"0\" height=\"315\" src=\"https://www.youtube.com/embed/L8r9t135_xY\" width=\"560\"\u003e\u003c/iframe\u003e\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\u003ciframe allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\" frameborder=\"0\" height=\"315\" src=\"https://www.youtube.com/embed/RE1Bl62ADeA\" width=\"560\"\u003e\u003c/iframe\u003e\n\u003c/div\u003e\n",
      "author":{  
        "id":"02116198639170264068",
        "displayName":"juan",
        "url":"https://www.blogger.com/profile/02116198639170264068",
        "image":{  
          "url":"//lh3.googleusercontent.com/zFdxGE77vvD2w5xHy6jkVuElKv-U9_9qLkRYK8OnbDeJPtjSZ82UPq5w6hJ-SA=s35"
        }
      },
      "replies":{  
        "totalItems":"0",
        "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/1922834480471121214/comments"
      },
      "labels":[  
        "artistas",
        "cine expandido",
        "obras",
        "Stan Brakhage"
      ]
    },
    {  
      "kind":"blogger#post",
      "id":"452727819046173587",
      "blog":{  
        "id":"6719264076843274138"
      },
      "published":"2018-11-06T16:40:00-08:00",
      "updated":"2018-11-06T16:40:20-08:00",
      "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/dGltZXN0YW1wOiAxNTQxNTUxMjIwNzU0Cm9mZnNldDogLTI4ODAwMDAwCg\"",
      "url":"http://jpvallejo.blogspot.com/2018/11/john-withney.html",
      "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/452727819046173587",
      "title":"John Withney",
      "content":"\u003cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003e\n\u003ciframe allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\" frameborder=\"0\" height=\"315\" src=\"https://www.youtube.com/embed/TbV7loKp69s\" width=\"560\"\u003e\u003c/iframe\u003e\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\u003ciframe allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\" frameborder=\"0\" height=\"315\" src=\"https://www.youtube.com/embed/ZrKgyY5aDvA\" width=\"560\"\u003e\u003c/iframe\u003e\n\n\u003cbr /\u003e\nPionero en la creación de imágenes por ordenador.&nbsp;\u003c/div\u003e\n",
      "author":{  
        "id":"02116198639170264068",
        "displayName":"juan",
        "url":"https://www.blogger.com/profile/02116198639170264068",
        "image":{  
          "url":"//lh3.googleusercontent.com/zFdxGE77vvD2w5xHy6jkVuElKv-U9_9qLkRYK8OnbDeJPtjSZ82UPq5w6hJ-SA=s35"
        }
      },
      "replies":{  
        "totalItems":"0",
        "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/452727819046173587/comments"
      },
      "labels":[  
        "artistas",
        "cine expandido",
        "investigación",
        "máquinas de imagen",
        "obras",
        "Slit Scan Motion Picture",
        "software"
      ]
    },
    {  
      "kind":"blogger#post",
      "id":"2403108397730586033",
      "blog":{  
        "id":"6719264076843274138"
      },
      "published":"2018-05-12T16:04:00-07:00",
      "updated":"2018-05-12T16:04:12-07:00",
      "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/dGltZXN0YW1wOiAxNTI2MTY2MjUyNTc1Cm9mZnNldDogLTI1MjAwMDAwCg\"",
      "url":"http://jpvallejo.blogspot.com/2018/05/paul-prudence.html",
      "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/2403108397730586033",
      "title":"Paul Prudence",
      "content":"\u003cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003e\n\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;\"\u003e\u003ca href=\"http://www.paulprudence.com/\"\u003ehttp://www.paulprudence.com/\u003c/a\u003e\u003c/span\u003e\u003cbr /\u003e\n\u003cbr /\u003e\n\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;\"\u003e\u003ca href=\"http://www.dataisnature.com/\"\u003ehttp://www.dataisnature.com/\u003c/a\u003e\u003c/span\u003e\u003cbr /\u003e\n\u003cbr /\u003e\n\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;\"\u003ePaul Prudence es un artista audiovisual británico.&nbsp;\u003c/span\u003e\u003c/div\u003e\n",
      "author":{  
        "id":"02116198639170264068",
        "displayName":"juan",
        "url":"https://www.blogger.com/profile/02116198639170264068",
        "image":{  
          "url":"//lh3.googleusercontent.com/zFdxGE77vvD2w5xHy6jkVuElKv-U9_9qLkRYK8OnbDeJPtjSZ82UPq5w6hJ-SA=s35"
        }
      },
      "replies":{  
        "totalItems":"0",
        "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/2403108397730586033/comments"
      },
      "labels":[  
        "artistas",
        "cine expandido",
        "investigación",
        "Paul Prudence",
        "software",
        "sonido"
      ]
    },
    {  
      "kind":"blogger#post",
      "id":"2197792464760194974",
      "blog":{  
        "id":"6719264076843274138"
      },
      "published":"2018-05-12T14:30:00-07:00",
      "updated":"2018-05-12T14:30:57-07:00",
      "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/dGltZXN0YW1wOiAxNTI2MTYwNjU3NTg1Cm9mZnNldDogLTI1MjAwMDAwCg\"",
      "url":"http://jpvallejo.blogspot.com/2018/05/clandestina-weekend-nerd.html",
      "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/2197792464760194974",
      "title":"Clandestina weekend Nerd",
      "content":"\u003cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003e\n\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif;\"\u003e\u003ca href=\"https://www.facebook.com/groups/mccwn/\"\u003ehttps://www.facebook.com/groups/mccwn/\u003c/a\u003e\u003c/span\u003e\u003cbr /\u003e\n\u003cbr /\u003e\n\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;\"\u003eGrupo en Facebook de intercambio de información de todo lo relacionado con el mundo de la cultura digital, media arts, tecnología, programación, etc.\u003c/span\u003e\u003c/div\u003e\n",
      "author":{  
        "id":"02116198639170264068",
        "displayName":"juan",
        "url":"https://www.blogger.com/profile/02116198639170264068",
        "image":{  
          "url":"//lh3.googleusercontent.com/zFdxGE77vvD2w5xHy6jkVuElKv-U9_9qLkRYK8OnbDeJPtjSZ82UPq5w6hJ-SA=s35"
        }
      },
      "replies":{  
        "totalItems":"0",
        "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/2197792464760194974/comments"
      },
      "labels":[  
        "digital culture",
        "social network"
      ]
    },
    {  
      "kind":"blogger#post",
      "id":"8792876415054950535",
      "blog":{  
        "id":"6719264076843274138"
      },
      "published":"2018-05-12T14:03:00-07:00",
      "updated":"2018-05-12T14:03:48-07:00",
      "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/dGltZXN0YW1wOiAxNTI2MTU5MDI4NjgwCm9mZnNldDogLTI1MjAwMDAwCg\"",
      "url":"http://jpvallejo.blogspot.com/2018/05/77-million-paintings-brian-eno.html",
      "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/8792876415054950535",
      "title":"77 million paintings. Brian Eno",
      "content":"\u003cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003e\n\u003cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003e\n\u003ciframe width=\"320\" height=\"266\" class=\"YOUTUBE-iframe-video\" data-thumbnail-src=\"https://i.ytimg.com/vi/YQllM0qx3c0/0.jpg\" src=\"https://www.youtube.com/embed/YQllM0qx3c0?feature=player_embedded\" frameborder=\"0\" allowfullscreen\u003e\u003c/iframe\u003e\u003c/div\u003e\n\u003cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003e\n\u003cbr /\u003e\u003c/div\u003e\n\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;\"\u003e77 million paintings (2016) es una instalación diseñada por el artista audiovisual Brian Eno, en la cuál se pone en cuestión la dimensión temporal de la obra; al tratarse de una obra generativa se calcula que pasarían varios millones de años para que una combinación sonora y visual vuelva a repetirse. La obra estuvo en montada en el CCK durante el año 2017.&nbsp;\u003c/span\u003e\u003cbr /\u003e\n\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;\"\u003e\u003cbr /\u003e\u003c/span\u003e\n\u003cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003e\n\u003ca href=\"http://www.cck.gob.ar/libraries/TimThumb/timthumb.inc.php?src=/files/eventos/1482875476_enocarrusel02.png&amp;w=730&amp;h=485\" imageanchor=\"1\" style=\"margin-left: 1em; margin-right: 1em;\"\u003e\u003cimg border=\"0\" src=\"http://www.cck.gob.ar/libraries/TimThumb/timthumb.inc.php?src=/files/eventos/1482875476_enocarrusel02.png&amp;w=730&amp;h=485\" data-original-height=\"485\" data-original-width=\"730\" /\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;\"\u003e\u003cbr /\u003e\u003c/span\u003e\u003c/div\u003e\n",
      "author":{  
        "id":"02116198639170264068",
        "displayName":"juan",
        "url":"https://www.blogger.com/profile/02116198639170264068",
        "image":{  
          "url":"//lh3.googleusercontent.com/zFdxGE77vvD2w5xHy6jkVuElKv-U9_9qLkRYK8OnbDeJPtjSZ82UPq5w6hJ-SA=s35"
        }
      },
      "replies":{  
        "totalItems":"0",
        "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/8792876415054950535/comments"
      },
      "labels":[  
        "Brian Eno",
        "cine expandido",
        "instalación",
        "música",
        "obras",
        "software",
        "sonido"
      ]
    },
    {  
      "kind":"blogger#post",
      "id":"8081671775170901303",
      "blog":{  
        "id":"6719264076843274138"
      },
      "published":"2018-05-12T13:45:00-07:00",
      "updated":"2018-05-12T13:45:11-07:00",
      "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/dGltZXN0YW1wOiAxNTI2MTU3OTExNzQ1Cm9mZnNldDogLTI1MjAwMDAwCg\"",
      "url":"http://jpvallejo.blogspot.com/2018/05/bloom-brian-eno.html",
      "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/8081671775170901303",
      "title":"Bloom. Brian Eno",
      "content":"\u003cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003e\n\u003cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003e\n\u003ciframe width=\"320\" height=\"266\" class=\"YOUTUBE-iframe-video\" data-thumbnail-src=\"https://i.ytimg.com/vi/dzC1hjP-odM/0.jpg\" src=\"https://www.youtube.com/embed/dzC1hjP-odM?feature=player_embedded\" frameborder=\"0\" allowfullscreen\u003e\u003c/iframe\u003e\u003c/div\u003e\n\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;\"\u003e\u003cbr /\u003e\u003c/span\u003e\n\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;\"\u003eBloom (2008) es una aplicación para iOS desarrollada por el artista británico Brian Eno para la composición de piezas sonoras y visuales generativas a partir de la interacción del usuario con la pantalla.&nbsp;\u003c/span\u003e\u003c/div\u003e\n",
      "author":{  
        "id":"02116198639170264068",
        "displayName":"juan",
        "url":"https://www.blogger.com/profile/02116198639170264068",
        "image":{  
          "url":"//lh3.googleusercontent.com/zFdxGE77vvD2w5xHy6jkVuElKv-U9_9qLkRYK8OnbDeJPtjSZ82UPq5w6hJ-SA=s35"
        }
      },
      "replies":{  
        "totalItems":"0",
        "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/8081671775170901303/comments"
      },
      "labels":[  
        "aplicación",
        "Brian Eno",
        "investigación",
        "música",
        "sinestesia",
        "software",
        "sonido"
      ]
    },
    {  
      "kind":"blogger#post",
      "id":"1700742664959825225",
      "blog":{  
        "id":"6719264076843274138"
      },
      "published":"2018-05-12T13:14:00-07:00",
      "updated":"2018-05-12T16:08:03-07:00",
      "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/dGltZXN0YW1wOiAxNTI2MTY2NDgzNzg4Cm9mZnNldDogLTI1MjAwMDAwCg\"",
      "url":"http://jpvallejo.blogspot.com/2018/05/learning-to-see.html",
      "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/1700742664959825225",
      "title":"Learning to see",
      "content":"\u003cdiv dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\"\u003e\n\u003ciframe allowfullscreen=\"\" frameborder=\"0\" height=\"360\" mozallowfullscreen=\"\" src=\"https://player.vimeo.com/video/260612034\" webkitallowfullscreen=\"\" width=\"640\"\u003e\u003c/iframe\u003e\u003cbr /\u003e\n\u003cbr /\u003e\n\u003ciframe allowfullscreen=\"\" frameborder=\"0\" height=\"360\" mozallowfullscreen=\"\" src=\"https://player.vimeo.com/video/242498070\" webkitallowfullscreen=\"\" width=\"640\"\u003e\u003c/iframe\u003e\u003cbr /\u003e\n\u003cbr /\u003e\n\u003cspan style=\"font-family: &quot;helvetica neue&quot; , &quot;arial&quot; , &quot;helvetica&quot; , sans-serif; font-size: x-small;\"\u003eEs un proyecto de inteligencia artificial y machine learning en el cuál se le enseña a un programa a generar un sentido de acuerdo a lo capturado por una cámara y a su memoria de las imágenes que ya vio.&nbsp;\u003c/span\u003e\u003cbr /\u003e\n\u003cspan style=\"font-family: &quot;helvetica neue&quot; , &quot;arial&quot; , &quot;helvetica&quot; , sans-serif; font-size: x-small;\"\u003e\u003ca href=\"http://www.memo.tv/learning-to-see-you-are-what-you-see/\" style=\"font-family: Times; font-size: medium;\" target=\"_blank\"\u003e\u003cspan style=\"font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: x-small;\"\u003ehttp://www.memo.tv/learning-to-see-you-are-what-you-see/\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003cbr /\u003e\n\u003cspan style=\"font-family: &quot;helvetica neue&quot; , &quot;arial&quot; , &quot;helvetica&quot; , sans-serif; font-size: x-small;\"\u003e\u003cbr /\u003e\u003c/span\u003e\u003c/div\u003e\n",
      "author":{  
        "id":"02116198639170264068",
        "displayName":"juan",
        "url":"https://www.blogger.com/profile/02116198639170264068",
        "image":{  
          "url":"//lh3.googleusercontent.com/zFdxGE77vvD2w5xHy6jkVuElKv-U9_9qLkRYK8OnbDeJPtjSZ82UPq5w6hJ-SA=s35"
        }
      },
      "replies":{  
        "totalItems":"0",
        "selfLink":"https://www.googleapis.com/blogger/v3/blogs/6719264076843274138/posts/1700742664959825225/comments"
      },
      "labels":[  
        "inteligencia artificial",
        "investigación",
        "machine learning",
        "obras",
        "software"
      ]
    }
  ],
  "etag":"\"NXBHOy2vAlMHFQbN3g17YG1AE10/MjAxOC0xMS0wN1QxMzowNzoxMC4zNjVa\""
}

did you try my “sub” string handling on it?
because i understand that question like you just want the link out of that string
what is a JSON element,
but the question then has nothing to do with JSON, only with checking on Sub-String??


a other good string function is
https://processing.org/reference/match_.html
so first check if there is a LINK inside
and if yes, take it out

JSONObject json;

void setup() {
  json = new JSONObject();
  json.setString("content", "<a href=\"https://www.youtube.com/watch?v=r7OMvBtV0l4\">https://www.youtube.com/watch?v=r7OMvBtV0l4</a>");
  //println(json);
  String test = json.getString("content");
  // now check if there is a link in that string
  String[] m = match(test, "href=");
  printArray(m);
  println(test);
  if ( m[0] != null) {
    println("yes, this JSON element contains a LINK");
    String[] q = splitTokens(test, "\"");
    printArray(q);
    println("link: "+q[1]);
  }
}

there should be a way in p5.js to do similar

1 Like

Do you mean plain text without html, or the full html of the “content”?

Do you mean save the link separately? When you say “conserve the format”–the html is the format. Do you want to just leave it as html?

Also, what do you want to happen if the post contains multiple links?

Ah. Well, that is totally different. JSON handling is native in p5.js / JavaScript, and you can search and retrieve html elements as well.

I am not a p5.js expert, but here is a little something to get you started on basic access – you load the JSON, grab each content field, and parse each content string into HTML elements and add them to a list. Then you can loop through and print them out – or you could parse them in various ways by getting children (‘div’) (‘a’) or getting links, and getting attributes (‘href’).

Here is an example:

Links from Blogger content
https://editor.p5js.org/jeremydouglass/sketches/_N0SJKDV3

Note that it requires you to enter your API key at the top to run. You should not post your API key to forums or save it to public sketches, as it could get taken and used by somebody else.

47%20AM

Note that your question talks about the JSON as if it is a file, and you have loaded that file as a string, but you say you have a p5.js sketch and this is Google API data – that suggests that it is a JSON object in memory, and you don’t need to “clean” it at all. Those JSON character escapes that you are seeing are automatically removed when you retrieve the values, so all you need to extract is the link. For example, the “content” at the bottom line of the screenshot is JSON escaped, but once it is retrieved (in the top line of the screenshot) it isn’t anymore. Ditto the URL is retrieved without string parsing – have Javascript and the browser retrieve href attributes for you.

Please, please don’t try to parse raw HTML strings with splits, substitutions, or regular expressions. For why, see: https://stackoverflow.com/a/1732454/7207622

…although note also that this code fails to find one of the links – centerforvisualmusic.org – because it is plain text, not an “a href=” link value. Retrieving those requires different steps – and that might involve string parsing, depending on what you are trying to recover. I’ve added a simple raw text URL finder to the sketch to show that case as well – there may be a more elegant way of doing it, I’m not sure.

2 Likes