json

Join JSON array field with string field in mysql

岁酱吖の 提交于 2021-02-09 09:17:32
问题 I am looking for records in table 2 whose id exist in the values of nums field (JSON) in table 1. table1 id | nums (JSON) ---+------------------- 1 | ["1","2","3","4"] 2 | ["7","8","5","6"] 3 | ["9","10","3","4"] table2 id | ---+ 1 | 2 | 53 | 63 | I would like to get the next result. rows desired id | ---+ 1 | 2 | I am using 5.7 mysql version. 回答1: If I understand correctly: select t2.id from table2 t2 where exists (select 1 from table1 where json_contains(nums, t2.id) ); You may need to cast

cannot extract elements from a scalar

狂风中的少年 提交于 2021-02-09 09:14:10
问题 I have 2 tables company and contacts. Contacts has addresses JSONB column. I tried a select statement with a join on contacts.linked_to_company and using jsonb_array_elements(company.addresses) but I get error 'cannot extract elements from a scalar' which I understand is because some entries do have [null] in column address. I have seen answers to use coalesce or a CASE statement. Coalesce I could get to not work and CASE example is in the select statement how do use it in a join? Here is the

How to flatten a json with nested lists by Jayway JsonPath?

半腔热情 提交于 2021-02-09 08:28:11
问题 Currently I need to process some json results based on configuration but not hard code. For example, with the json as follows { data: [{ orderNo: "CG8310150", details: [{ skuId: 4384, amount: 2 }, { skuId: 4632, amount: 5 }] }, { orderNo: "CG8310151", details: [{ skuId: 4384, amount: 3 }] }] } I want the result as follows [{ orderNo: "CG8310150", skuId: 4384, amount: 2 }, { orderNo: "CG8310150", skuId: 4632, amount: 5 }, { orderNo: "CG8310151", skuId: 4384, amount: 3 }] If anyone has the

How to flatten a json with nested lists by Jayway JsonPath?

房东的猫 提交于 2021-02-09 08:27:29
问题 Currently I need to process some json results based on configuration but not hard code. For example, with the json as follows { data: [{ orderNo: "CG8310150", details: [{ skuId: 4384, amount: 2 }, { skuId: 4632, amount: 5 }] }, { orderNo: "CG8310151", details: [{ skuId: 4384, amount: 3 }] }] } I want the result as follows [{ orderNo: "CG8310150", skuId: 4384, amount: 2 }, { orderNo: "CG8310150", skuId: 4632, amount: 5 }, { orderNo: "CG8310151", skuId: 4384, amount: 3 }] If anyone has the

How to serialise Enums as both Object Shape and default string?

穿精又带淫゛_ 提交于 2021-02-09 07:53:28
问题 For an enum with attributes, eg: public enum Thing { THING_A("a"), THING_B("b"); private String thing; private Thing(String thing) { this.thing = thing; } // Getters... } Jackson serializes as the name of the values, eg: mapper.writeValueAsString(Thing.THING_A)); // "THING_A" If we add the annotation to treat serialisation as an object: @JsonFormat(shape = JsonFormat.Shape.OBJECT) it will serialize the attributes: mapper.writeValueAsString(Thing.THING_A)); // "{"thing":"a"}" I'd like to be

Check if an element is contained in the values ​(array) of a json column in MySql

五迷三道 提交于 2021-02-09 07:38:38
问题 I have the following values ​​inside a cell of a json column in MySql: { "produttori": [ "8", "9" ], "articoli_alternativi": [ "3", "9" ], "articoli_accessori": [ "5", "6", "7", "8" ], "tecnologie": [], "fornitori": [ "9", "8" ], "classificazioni": [ "3", "4" ] } I would like to make a query that extracts data based on the existence of a value in the array at the fornitori key. For now I've tried this: query = 'SELECT nome, formulati_commerciali FROM articolo WHERE JSON_CONTAINS(JSON_EXTRACT

Check if an element is contained in the values ​(array) of a json column in MySql

倖福魔咒の 提交于 2021-02-09 07:32:46
问题 I have the following values ​​inside a cell of a json column in MySql: { "produttori": [ "8", "9" ], "articoli_alternativi": [ "3", "9" ], "articoli_accessori": [ "5", "6", "7", "8" ], "tecnologie": [], "fornitori": [ "9", "8" ], "classificazioni": [ "3", "4" ] } I would like to make a query that extracts data based on the existence of a value in the array at the fornitori key. For now I've tried this: query = 'SELECT nome, formulati_commerciali FROM articolo WHERE JSON_CONTAINS(JSON_EXTRACT

Which is the suitable database for storing a large JSON? [closed]

自古美人都是妖i 提交于 2021-02-09 07:16:49
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question I have only one large JSON file. For example, { "Name": "Motor_M23", "AASID": { "IDType": "URI", "IDSpec": "http://acplt.org/AAS/Motor_M23" }, "AssetID": { "IDType": "URI", "IDSpec": "http://acplt.org/Assets/Motor_M23" }, "Header": {

Which is the suitable database for storing a large JSON? [closed]

ⅰ亾dé卋堺 提交于 2021-02-09 07:14:08
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question I have only one large JSON file. For example, { "Name": "Motor_M23", "AASID": { "IDType": "URI", "IDSpec": "http://acplt.org/AAS/Motor_M23" }, "AssetID": { "IDType": "URI", "IDSpec": "http://acplt.org/Assets/Motor_M23" }, "Header": {

Json string from LocalDateTime(java 8) in Spring MVC

徘徊边缘 提交于 2021-02-09 07:10:59
问题 have trouble in LocalDateTime(Java 8) Formatting in Spring MVC framework my VO is like under code in mySQL w_date field is DATETIME and recode like "2015-12-25 23:18:22" public class HistoryBoard { @JsonFormat(pattern="yyyy-MM-dd") @DateTimeFormat(iso = DateTimeFormat.ISO.TIME) private LocalDateTime w_date; public LocalDateTime getW_date() { return w_date; } public HistoryBoard setW_date(String w_date) { DateTimeFormatter sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"); this.w_date