You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@incubator.apache.org by Joao Boto <bo...@boto.pro> on 2014/11/11 16:55:32 UTC

complex json file

i'm trying to understand how to read a complex json file..

i started with this json (but will work with a much more complex):
{
"name":{ "first":"Joe", "last":"Sixpack" },
"gender":"MALE",
"verified":false,
"userImage":"Rm9vYmFyIQ=="
}

trying to do what Kasper told me on
https://issues.apache.org/jira/browse/METAMODEL-38

I wrote the code below, but i can't get "first" and "last" fields..

SimpleTableDef custTable = new SimpleTableDef(
"customer",
new String[] {"name.first","name.last","gender","verified","userimage"}
);

SchemaBuilder schema = new SimpleTableDefSchemaBuilder("tester", custTable)
;
JsonDataContext dc = new JsonDataContext(new FileResource(new
File("src/test/resources/datafeed.json")),schema);
Table table = dc.getDefaultSchema().getTableByName("customer");
Column firstName = table.getColumnByName("name.first");
Column lastName = table.getColumnByName("name.last");
Column gender = table.getColumnByName("gender");
DataSet dataSet =
dc.query().from(table).select(firstName,lastName,gender).execute();
while (dataSet.next()) {
String sFirstName = (String) dataSet.getRow().getValue(firstName);
String sLastName = (String) dataSet.getRow().getValue(lastName);
String sGender = (String) dataSet.getRow().getValue(gender);
}

can someone tell me what I'm doing wrong or indicate which way to go?

thanks

Best regards

Fwd: complex json file

Posted by Henry Saputra <he...@gmail.com>.
I believe you meant to send it to dev@metamodel mailing list =)


---------- Forwarded message ----------
From: Joao Boto <bo...@boto.pro>
Date: Tue, Nov 11, 2014 at 7:55 AM
Subject: complex json file
To: general@incubator.apache.org


i'm trying to understand how to read a complex json file..

i started with this json (but will work with a much more complex):
{
"name":{ "first":"Joe", "last":"Sixpack" },
"gender":"MALE",
"verified":false,
"userImage":"Rm9vYmFyIQ=="
}

trying to do what Kasper told me on
https://issues.apache.org/jira/browse/METAMODEL-38

I wrote the code below, but i can't get "first" and "last" fields..

SimpleTableDef custTable = new SimpleTableDef(
"customer",
new String[] {"name.first","name.last","gender","verified","userimage"}
);

SchemaBuilder schema = new SimpleTableDefSchemaBuilder("tester", custTable)
;
JsonDataContext dc = new JsonDataContext(new FileResource(new
File("src/test/resources/datafeed.json")),schema);
Table table = dc.getDefaultSchema().getTableByName("customer");
Column firstName = table.getColumnByName("name.first");
Column lastName = table.getColumnByName("name.last");
Column gender = table.getColumnByName("gender");
DataSet dataSet =
dc.query().from(table).select(firstName,lastName,gender).execute();
while (dataSet.next()) {
String sFirstName = (String) dataSet.getRow().getValue(firstName);
String sLastName = (String) dataSet.getRow().getValue(lastName);
String sGender = (String) dataSet.getRow().getValue(gender);
}

can someone tell me what I'm doing wrong or indicate which way to go?

thanks

Best regards

Re: complex json file

Posted by Henry Saputra <he...@gmail.com>.
Hi Joao,

Looks like you were trying to send email to dev@metamodel incubator instead.

I have forwarded your original email to dev@ list for Apache MetaModel
incubating.

- Henry

On Tue, Nov 11, 2014 at 7:55 AM, Joao Boto <bo...@boto.pro> wrote:
> i'm trying to understand how to read a complex json file..
>
> i started with this json (but will work with a much more complex):
> {
> "name":{ "first":"Joe", "last":"Sixpack" },
> "gender":"MALE",
> "verified":false,
> "userImage":"Rm9vYmFyIQ=="
> }
>
> trying to do what Kasper told me on
> https://issues.apache.org/jira/browse/METAMODEL-38
>
> I wrote the code below, but i can't get "first" and "last" fields..
>
> SimpleTableDef custTable = new SimpleTableDef(
> "customer",
> new String[] {"name.first","name.last","gender","verified","userimage"}
> );
>
> SchemaBuilder schema = new SimpleTableDefSchemaBuilder("tester", custTable)
> ;
> JsonDataContext dc = new JsonDataContext(new FileResource(new
> File("src/test/resources/datafeed.json")),schema);
> Table table = dc.getDefaultSchema().getTableByName("customer");
> Column firstName = table.getColumnByName("name.first");
> Column lastName = table.getColumnByName("name.last");
> Column gender = table.getColumnByName("gender");
> DataSet dataSet =
> dc.query().from(table).select(firstName,lastName,gender).execute();
> while (dataSet.next()) {
> String sFirstName = (String) dataSet.getRow().getValue(firstName);
> String sLastName = (String) dataSet.getRow().getValue(lastName);
> String sGender = (String) dataSet.getRow().getValue(gender);
> }
>
> can someone tell me what I'm doing wrong or indicate which way to go?
>
> thanks
>
> Best regards

---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@incubator.apache.org
For additional commands, e-mail: general-help@incubator.apache.org