Skip to content

Commit

Permalink
Implement insertOrReplaceField
Browse files Browse the repository at this point in the history
  • Loading branch information
bmjames committed Feb 28, 2014
1 parent a0ee044 commit cf4cfe5
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/main/scala/com/gu/json/Cursor.scala
Expand Up @@ -127,6 +127,9 @@ case class Cursor[J](focus: J, path: Path[J])(implicit J: JsonLike[J]) {
def insertField(name: String, value: J): Option[Cursor[J]] =
J.asObj(focus) map (fields => Cursor(value, InObject(name, Nil, fields) :: path))

def insertOrReplaceField(name: String, value: J): Option[Cursor[J]] =
field(name).map(_.replace(value)) orElse insertField(name, value)

/** Move the focus to the named field, at the same level as the current focus in an object */
def sibling(name: String): Option[Cursor[J]] =
path match {
Expand Down

0 comments on commit cf4cfe5

Please sign in to comment.