Leveraging the powerful SQLite JSON functions, my intention is to fetch a specific value by considering the neighboring values

Suppose I have a JSON structure and I want to extract the age values associated with the name "Chris" in the Array key.

{
    "Array": [
        {
            "age": "65",
            "name": "Chris"
        },
        {
            "age": "20",
            "name": "Mark"
        },
        {
            "age": "23",
            "name": "Chris"
        }
    ]
}

This JSON is stored in my database under the Json column. Therefore, I aim to retrieve the ages 65 and 23 since both individuals have the name Chris.

Answer №1

To extract the names and ages from the json array in each row of the table, you can utilize the table-valued function called json_each(). Additionally, employ the json_extract() function to filter the rows specifically for the name 'Chris', allowing retrieval of his age:

The following query will accomplish this task:
SELECT json_extract(j.value, '$.name') as Name, 
       json_extract(j.value, '$.age') as Age
FROM your_table_name t JOIN json_each(t.json_column_name, "$.Array") j
WHERE json_extract(j.value, '$.name') = 'Chris';

In the above query, ensure that you replace 'your_table_name' with the actual name of your table, and substitute 'json_column_name' with the corresponding name of your JSON column.

If you require further clarification or examples, refer to the provided demo.

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

A guide to displaying the properties of a JSON document

Can someone assist me in extracting only the country data from the information fetched through this API call? Many thanks! import requests import json url = "https://randomuser.me/api/" data = requests.get(url).json() print(data) ...

Is it necessary to reset the variable following an ajax request?

There are two ajax functions in my code: $("body").on("click", ".follow", function() { var followingId = $(this).data("following"); var followData = {"following_id" : followingId} $(this).addClass('disabled'); $.ajax({ ur ...

Displaying data on the user interface in Angular by populating it with information from the form inputs

I am working on a project where I need to display data on the screen based on user input received via radio buttons, and apply specific conditions. Additionally, I require assistance in retrieving the id of an object when the name attribute is chosen from ...

Python: decoding a byte stream string on the server end

When transmitting my JSON data through Python 3 using urllib.request, I encounter an issue. data = {"a": "1"} req = urllib.request.Request('https://example.com', data=json.dumps(data).encode('utf8'), headers={'Content-Type': ...

The deployment of a module to the IoT edge device failed due to an error (ErrorCode:Argumentinvalid)

I'm currently facing some challenges in deploying a Modbus module from an IoT hub to an IoT edge device. For the Docker Image, I utilized: mcr.microsoft.com/azureiotedge/modbus:1.0 The Container Create Option: (I included this because I am using thi ...

Create a key for QJsonObject using the current timestamp

I am trying to create a code that will write logs in JSON format with epoch timestamps. The expected log format should be like this: {234231412:{"user":"alex", "device":"HD-3432", "action":"connectin to server}} Unfortunately, the following code failed ...

Is the AJAX call returning JSON data?

Currently, I am utilizing AJAX technology to scrape player names and their respective ratings from a website. The approach I have chosen involves having AJAX return a JSON object which is then manipulated using jQuery to append each element of the JSON obj ...

Accessing a RESTful API using Django

Can a model field be created to utilize a REST API as a foreign key? I currently have two projects. The first project contains the following model in models.py: from django.db import models from django_countries.fields import CountryField from django.url ...

Develop a MySQL function that generates a nested JSON Array data structure

To efficiently create a stored procedure in MySQL that extracts specific fields from the database and constructs a formatted JSON object, follow these steps: Begin by initializing a base JSON object as illustrated below: { "form": "Exams tests", ...

A comparison between Protocol Buffers and the JSON and BSON formats

Can anyone provide insights on how Protocol Buffers stack up against BSON (binary JSON) or JSON in terms of performance characteristics? Wire size Serialization speed Deserialization speed These binary protocols seem ideal for transmission over HTTP. I& ...

Showing intricate JSON data in AngularJS

How can I effectively display complex JSON data containing boolean values, strings, and arrays? $scope.options = { "option_1" : "some string", "option_2" : true, "option_3" : [1.123456789, 0.123548912, -7.156248965], "option_4" : n ...

Mapping an Optional<Enum> with @RequestBody in Spring's MVC

I am working on a rest controller that includes the following method: @RequestMapping(value = "", method = { RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE }) public ResponseEntity<?> add(@Valid @RequestBody MyModel myModel, ...

Using multi-dimensional JSON arrays for posting requests through Ajax

Is it possible to serialize HTML fields in a multi-dimensional array format for AJAX post transmission? I tried using serializeArray but it only formats the first level of the array. The data I need to serialize includes name/value pairs like: name="cus ...

The rows sent to HTML/Bootstrap from Java through JSON do not neatly wrap across rows evenly

I am having trouble getting images to wrap evenly on an HTML/Bootstrap page that are retrieved by Java and passed through JSON. Despite my expectations, there is a third row created with only one image and a fifth row with 3 extra images. Additionally, whe ...

Using JSON to dynamically add data points to all series in Highcharts

I am looking to dynamically generate a chart that displays network usage over time. The number of series in the chart can vary depending on the number of network adapters present in the system at any given moment. I have developed a script that retrieves ...

The error message "Alamofire JSON POST response failed: Lost connection to the network" was displayed

Many individuals encounter this error for various reasons. I have yet to come across a solution that resolves my specific issue. In order to log my Alamofire requests, I utilize Timberjack. While all of my GET requests function properly and return JSON d ...

Inserting a variable into a JSON string

Within my code, I have a basic variable containing strings that are converted into a JSON object. My goal is to create an input field where a person's name can be entered and added to the text. The current setup looks like this var text = '{"st ...

Optimal Strategies for Interacting with a JSON REST API in Swift 2.0

As I transitioned to Swift, I quickly realized that a lot of the Sample Code I was using no longer functions in Swift 2.0. This has made it challenging for me as a beginner to navigate. I am seeking advice on the best practices for interacting with a REST ...

Swift Parsing JSON

How can I extract data from a JSON file that includes numerical elements? I need to retrieve specific information from a JSON object in Swift, but some of the keys are numbers and I'm unsure how to access those values. I've been able to successf ...

The execute command within a function is malfunctioning in Python 3.5

Currently, I am working on a python program that aims to parse JSON files based on their tags using the Python `exec` function. However, I encountered an issue where the program fails when the `exec` statement is within a function. RUN 1: Exec in a functi ...