Extract only the values from a JSON string using Regular Expressions

Need help cutting out specific values from a JSON String in Flutter/Dart.

Here's an example of the JSON String:

  [{"insert":"Test12\n"},{"insert":"Test1","attributes":{"b":true}},{"insert":"\nTest"},{"insert":"\n","attributes":{"block":"quote"}},{"insert":"Test","attributes":{"s":true}},{"insert":"\nTest"},{"insert":"\n","attributes":{"block":"ol"}},{"insert":"Test"},{"insert":"\n","attributes":{"block":"ol"}},{"insert":"Test"},{"insert":"\n","attributes":{"block":"ul"}},{"insert":{"_type":"hr","_inline":false}},{"insert":"\n"},{"insert":"Test","attributes":{"i":true,"u":true,"s":true,"b":true}},{"insert":"\n\n"}]

The goal is to extract only the values after the "insert" key. Thus, the desired result should be:

Test12 Test1 Test Test Test Test Test Test

Characters like "", . {} \n are not needed.

The term "Test" can represent various strings.

I've tried using RegEx but haven't been successful. Is RegEx the right approach for this task?

Thank you in advance.

Answer №1

If you have some JSON data, it's a good idea to decode it like this:

var jsonData =  '[{"name":"John"},{"age":30}]';
jsonData = jsonData.replaceAll('\n', '\\n');
// Using jsonDecode() will convert the JSON into primitive objects.
var decodedData = jsonDecode(jsonData) as List<dynamic>;
var names = [ for(var item in decodedData) item["name"]];
for(var name in names)
  print(name);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the significance of the error message "The Type 'Any' does not align with the 'Sequence' protocol" when trying to iterate through a 'JSON' result?

Currently I am deepening my knowledge in Swift programming. My latest project involves creating an app that can extract historical data from a website and present it visually in the form of a chart. For this task, I have been utilizing Alamofire to handle ...

Exploring a JSON file with Python using regular expressions or the Whoosh library

I have extracted data from over 5 e-commerce websites and stored it in a large JSON file as a collection of dictionaries, such as: { "url": "https://www.amazon.com/category/product_1", "price": 539, "product_code": ["x123"], "page_title": "Smar ...

Having difficulty retrieving parsing information with JSON

I am currently working on a project that involves parsing data from a URL using JSON. However, I seem to be facing an issue with my code. Even though there are no error messages displayed, when I run the code it just shows a blank screen. I'm struggl ...

Guide to creating a dynamic form using Phonegap and jQuery Mobile

Currently, I am working on an iPhone and Android app using Phonegap and jQueryMobile. The app receives a JSON with a form that was generated by my ruby on rails web application. However, I have encountered a significant issue. The form is quite large, con ...

What is the correct way to show a JavaScript response on the screen?

Here is the JavaScript code I used to call the server API: <script type='text/javascript'> call_juvlon_api(apikey, 'getAvailableCredits', '', function(response) { document.getElementById('show').innerHT ...

Extracting JSON data from an HTML page using identical field names

I am encountering a problem with scraping a page and extracting JSON from it. The <script type="text/x-magento-init"> tag contains the JSON data that I am attempting to retrieve. However, when using .find('script',{'type&apos ...

Struggling to transfer information from a JSON document to a MYSQL database using PHP, however, it seems the data isn't aligning with the required format

Currently facing an issue with inserting JSON data into MYSQL database using PHP. The data is not aligning properly with the codes written. Extracted raw data from a transportation website: "d": [ { "CreateDate": "/Date(1465439077603)/", ...

Manipulating web elements by traversing through selected identifiers in LocalStorage and eliminating them from the document layout

I have a multitude of localStorage keys, including ones labeled Cart, Viewed, and Trash. There are two aspects to my query: 1) What is the most efficient way to loop through the item IDs in localStorage and add a class or data attribute to the correspond ...

Looking to set up a web service that can handle incoming posts, but unsure about the best way to send a response back to jQuery

Good morning, I have a Go code that processes a JSON post request and performs certain actions. However, I am looking to send back either the result or a message to jQuery. package main import ( "fmt" "log" "net/http" "encoding/json" ...

JavaScript string: Use regex to find and replace with position index

I'm not very familiar with regex, so I'm curious about the process of replacing a section in a string based on a regex pattern where the index is part of the identified section. Let's consider this example string: let exampleStr = "How do ...

Is there a way to trigger a function from a specific div element and showcase the JSON data it retrieves in

I am working with a React JS code page that looks like this: import React, { useState } from "react"; import { Auth, API } from "aws-amplify"; function dailyFiles(props) { const [apiError502, setApiError502] = useState(false); // Extracted into a re ...

The JSON index is beyond the range [0..1)

I have been attempting to retrieve data from a MySql database using Volley in a JSONArray. The PHP script used to fetch rows from the table is shown below: <?php ob_start(); header('Content-Type: application/json'); $con=mysqli_connect("local ...

Serialize long values in exponential notation format using Spring MVC's REST JsonSerializer

My Spring MVC REST application has a custom Json serializer (for ObjectMapper) for handling LocalDate objects: public class DateSerializer extends JsonSerializer<LocalDate> { public LocalDateSerializer() { super(); } @Overr ...

How can I obtain tabular output for Boto3 | Python data?

When using the AWS CLI, you have the option to set the output format as either json or table. While I am able to obtain JSON output using json.dumps, is there a way to achieve output in table format? I attempted to use pretty table but did not succeed. ...

What is the process for assigning a value of type NSURL to type UIimage?

Hey there, I've got a Json file: { "Name":"Car", "Picture":"http://www.starpropertiesindia.com/blog/wp-content/uploads/2016/08/kochi1.jpg", "Description":"Ford" } that contains information about a car which includes name, picture and descri ...

Utilizing Node.js to insert and retrieve unprocessed JSON data in MySQL

In my MySQL table, I have a column called jsonvalues with the data type set to blob. I am storing raw JSON values in this field as shown below: {"name":"john","mob":"23434"} However, when I retrieve these values from the database in Node.js, the JSON for ...

Searching with preg_match

<?php $content = " {php {php 1 php} {php 2 php} {php 3 php} php}"; How can I extract four separate strings? The first block: {php 1 php} {php 2 php} {php 3 php} The second one: 1 The third part: 2 And finally, the fourth piece: 3 ...

The size of objects on canvas is not consistent when loading with fabric.js loadFromJSON

Click here to view the code var canvas = new fabric.Canvas('canvas_1'); var canvas2 = new fabric.Canvas('canvas_2'); var imgObj = new Image(); imgObj.src = "https://gtaprinting.ca/wp-content/uploads/2021/05/blank-t-shirt-front-gre ...

When using json_decode, the first character of string numbers will have the zero removed

When passing a phone number (which is a string) with a leading zero to the json_decode function, it ends up removing the first zero character and converting it into a float number. $phoneNumber = '09178882356'; //dynamic value echo json_decode($ ...

What are the reasons for the failure of parsing this specific Twitter JSON file using Angular $http, and how can I troubleshoot and resolve the issue

After finding a JSON example on the following website (located at the bottom): , I decided to save it to a file on my local system and attempt to retrieve it using Angular's $http service as shown below: To begin, I created a service: Services.Twitt ...