Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Previously I was using a json file with the following format:

[{"lat":43.788458853157117,"lng":-79.282781549043008,"category":"volunteer","name":"Rita","url":"", "description":"xxx is a member of 13"},{"lat":43.7,"lng":-79.4,"category":"organization","name":"TCAN","url":"http://tcan.ca","description":"Lorem ipsum"}]

Now I am attempting to generate the json file from a Drupal site and am getting the following structure. How can I reference the lowest level fields. I have looked at examples using d3.net but have not found any that apply.

{
    "organizations": [
        {
            "member": {
                "field_category": "organization",
                "body": "A network of organizations in Toronto devoted to climate change mitigation and adaptation.",
                "URL": "xxx.ca",
                "title": "Toronto Climate Action Network",
                "field_lat": 43.7,
                "field_long": -79.4
            }
        },
        {
            "member": {
                "field_category": "abc",
                "body": "xxx.",
                "URL": "",
                "title": "yyy",
                "field_lat": 43.7,
                "field_long": -79.28
            }
        }
    ]
}
share|improve this question
add comment

1 Answer

Assuming that your data is stored in the variable data:

var bottom = data.organizations.map(function(d) { return d.member; });
share|improve this answer
 
I am using the following code to access the json file - how would this fit in? d3.json("d3_files/json/members4.json",function(error,data){ circles.selectAll("circle") .data(data) .enter() .append("image") .attr("xlink:href", function(data) { return lookupTable[data.category](); }) // end attr .attr("width", 64) // dimention of image .attr("height", 64) .attr("transform",function(data){ return"translate("+projection([data.lng,data.lat])+")" }) // end transform attr –  PatriciaW 20 hours ago
 
In particular how would I reference the "body" field? –  PatriciaW 20 hours ago
 
You would use bottom instead of data in your D3 code after the conversion. To reference the body field, you can use something like d3.selectAll("text").data(bottom).enter().append("text").text(function(d) { return d.body; }). –  Lars Kotthoff 11 hours ago
 
Lars, many thanks. That really helped me and I got it to work. Clearly I am still missing some fundamentals. –  PatriciaW 5 hours ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.