in Education by
My question is a bit complicated and I wasted whole day without any good effect I get from one place a such Json: {"vehicle":4,"year":2002} from another String : ["productCode","PL","productCode","DE"] I dont know how to convert it to key value object like: "productCode": "PL" because productCode duplicate I can not use hashmap :( and a string: "options":[] I wish at the end I get json: { "vehicle":4, "year":2002", "products":[ {"productCode":"PL"}, {"productCode":"DE"} ], "options":[] } Could someone help me please :) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If you know you are going to encounter only productCode as a string in that list of elements, then remove it from the list and iterate over the remaining ones so that they can be added to a mutable list of maps. Later on, you can convert that Map to a JSON string using whichever library you have. In another case, assuming only keys are going to get repeated in a list of strings, just take out the repetitive element, treat that as your key and repeat the above-mentioned method. Rather than performing operation directly on the JSON string, I would say use dictionary/maps for manipulation, and at the end let your function return the final map and so that it can be converted into a JSON string. Let me know if that helps.

Related questions

0 votes
    In java, how can I parse json text to get value of variables like post_id ? Here is my json text { "page": { ... ": "1234567890" } ] } Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I was unable to find a solution that is identical with the issue I am trying to solve. If is a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I was unable to find a solution that is identical with the issue I am trying to solve. If is a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I am trying to merge 2 data frames by using the id and then trying to save the result in the JSON file. | |id|a|b ... |3|15|3, 12|6, 15 Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Computers manipulate data in many ways, and this manipulation is called- (A) upgrading (B) processing (C) batching ... ) None of these Select the correct answer from above options...
asked Dec 2, 2021 in Education by JackTerrance
0 votes
0 votes
    Cassandra supports which of the below API's to retrieve and manipulate data (1)Client API (2)All the options (3)Thrift API (4)Avro...
asked May 7, 2021 in Technology by JackTerrance
0 votes
    Cassandra supports which of the below API's to retrieve and manipulate data (1)Client API (2)All the options (3)Thrift API (4)Avro...
asked Apr 16, 2021 in Technology by JackTerrance
0 votes
    Advanced users can write ___ code to manipulate R objects directly. (a) C, C++ (b) C++, Java (c) ... Getting Started of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Advanced programmers can write ______ code to manipulate R objects. (a) Python (b) Java (c) C (d) Java ... Started of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    A ________ is a computer to which a user doesn't have physical access , which she can access or manipulate ... of computer network. Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    Which is the subset of SQL commands used to manipulate Oracle Database Structures, including tables? (a) ... Transaction Model topic in section Transactions of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    How does applet and servlet communicate? (a) HTTP (b) HTTPS (c) FTP (d) HTTP Tunneling I have been ... Technologies & Servlet of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    How is the dynamic interception of requests and responses to transform the information done? (a) servlet container ... Servlet of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
    Can anybody tell me how to send a mail to group of person by using JavaMail? I have tried but I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
...