ruby-on-railsrubyneo4j.rb

Neo4j.rb : as_json how to ignore root?


For Active record its working fine

ActiveRecord::Base.include_root_in_json = false

User.first.as_json

=> { "id" => 1, "name" => "Konata Izumi", "age" => 16,
     "created_at" => "2006/08/01", "awesome" => true}

When I use it for Neo4j.rb active node

Person.first.as_json

=> {"person"=> {" first_name"=>"Kay", "last_name" => "Wood",
    "email" => "wood.kay@kozey.co" } }

This how I am going to send repsosne by API, I don't need this root element Any help??


Solution

  • From the neo4j documentation :

    include_root_in_json

    When serializing ActiveNode and ActiveRel objects, should there be a root in the JSON of the model name.

    Default: true

    So you could just add

    config.neo4j.include_root_in_json = false
    

    in config/application.rb.