Json output to container

Vino akashvino79 at gmail.com
Fri Oct 30 18:20:31 UTC 2020


On Friday, 30 October 2020 at 17:56:22 UTC, Andre Pany wrote:
> On Friday, 30 October 2020 at 10:23:22 UTC, Vino wrote:
>> Hi,
>>
>>   Request your help on the below code
>>
>> Code:
>>
>> import asdf: parseJson;
>> import std.algorithm;
>> import std.container.array;
>> import std.stdio: writeln;
>> import std.typecons: Tuple, tuple;
>>
>> void main()
>> {
>>   string apidata1 = `{"items":
>>   [
>>     {"name":"T01","hostname":"test01","pool":"Development"},
>>     {"name":"T02","hostname":"test02","pool":"Quality"},
>>     {"name":"T03","hostname":"test03","pool":"Production"}
>>   ]
>>   }`;
>>   auto data = Array!(Tuple!(string, string, string)) 
>> (parseJson(apidata1)
>>              .filter!(a => a.(["items"].byElement))
>>              .map!(a => 
>> tuple(a.(["name"].get!string("default")), 
>> a.(["hostname"].get!string("default")), 
>> a.(["pool"].get!string("default")))));
>>   writeln(data[]);
>> }
>>
>> From,
>> Vino.B
>
> What do you want to achieve and what is the problem with the 
> code you posted?
>
> Kind regards
> Andre

Hi Andre,

    We wanted to store the output of the json data in array 
container, the main goal of this request is that we are currently 
planning to migrate our existing code which was written in PHP to 
D, and our existing code deal's with many api calls with json 
output, so we are evaluating the feasibility, of various json 
package's available in D, one of the code in our existing project 
is as below

Example code:
api1 : http://test.com/server
This api1 contains data "id" and "servername"

api2 :  http://test.com/type
This api2 contains data "servername" and "type"

api3 :  http://test.com/catagore
This api3 contains data "type" and "category"

so we fetch the data using the above api's and store the data in 
PHP multi dimensional array like "ID", "ServerName", "Type" and 
"category"(temporary storage) and then we update the information 
in this array into MySQL table.

From,
Vino.B




More information about the Digitalmars-d-learn mailing list